Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Erlang 调度初探
庄晓丹丹 2017/01/06
Ping-Pong
Ping-Pong
• ping_pong.ex
• Context Switch:1.x us on my machine(2.5 GHz
Intel Core i7).
Process Structure
• C Struct : erl_process.h
• PCB: process control block
• process id
• stack/heap position
• argument re...
Erlang Process
Stack and Heap
Process
来⾃自: http://www.cnblogs.com/me-sa/archive/2011/11/13/
erlang0014.html
Message Passing
• send / receive
• Coping message
• Sends a message to it self, doesn’t copy.
• binary 拷⻉贝引⽤用
• < 64 : pri...
Scheduler
• Reductions: 2000
• erl_vm.h :
• #define CONTEXT_REDS 2000 /* Swap process out after this number */
• erts_sched...
A Scheduler
图⽚片来⾃自 Google images
SMP
• Multiple processors => Multiple scheduler
• erl +S Schedulers:SchedulerOnline
• defaults to logical processors config...
SMP Schedulers
图⽚片来源:http://ithelp.ithome.com.tw/articles/10161709
Workload Balancing
• Check workload periodically by one scheduler
• Default period: 2000*2000 reductions.
• erl_process.c:...
Number of schedulers
Next active schedulers
Work migration
Memory Management
http://erlang.org/doc/man/erts_alloc.html
Garbage Collection
• Process heap: copying generational garbage
collector.
• 共享 Binary: 引⽤用计数
• https://www.erlang-solutio...
GC
Control GC
• erl +h min_heap_size
• spawn min_heap_size/min_bin_vheap_size
• :erlang.garbage_collect()
• Statistics:
• :er...
参考资料料
• http://www.diva-portal.org/smash/get/diva2:392243/
FULLTEXT01.pdf
• https://www.erlang-solutions.com/blog/erlang-1...
Erlang scheduler
Erlang scheduler
Upcoming SlideShare
Loading in …5
×

Erlang scheduler

4,596 views

Published on

Erlang 调度器初探。

Published in: Technology
  • Be the first to comment

Erlang scheduler

  1. 1. Erlang 调度初探 庄晓丹丹 2017/01/06
  2. 2. Ping-Pong
  3. 3. Ping-Pong • ping_pong.ex • Context Switch:1.x us on my machine(2.5 GHz Intel Core i7).
  4. 4. Process Structure • C Struct : erl_process.h • PCB: process control block • process id • stack/heap position • argument registers • program counter • stack • private heap : compound data structures, such as tuples, lists etc. • heap fragments: used when there is not enough free space in the heap and garbage collection cannot be performed to get more free memory.
  5. 5. Erlang Process
  6. 6. Stack and Heap
  7. 7. Process 来⾃自: http://www.cnblogs.com/me-sa/archive/2011/11/13/ erlang0014.html
  8. 8. Message Passing • send / receive • Coping message • Sends a message to it self, doesn’t copy. • binary 拷⻉贝引⽤用 • < 64 : private heap • >= 64 : 全局共享 • 推荐:⼩小消息,⼤大计算
  9. 9. Scheduler • Reductions: 2000 • erl_vm.h : • #define CONTEXT_REDS 2000 /* Swap process out after this number */ • erts_schedule in erl_process.c • consumes all its reductions • or pauses to wait for a message • Four priorities: low | normal | high | max • Four queues: ports, maximum, high, normal/low. • ports > max > high > normal/low • normal/low: skip a low priority process for a number of times • Round-Robin in queue.
  10. 10. A Scheduler 图⽚片来⾃自 Google images
  11. 11. SMP • Multiple processors => Multiple scheduler • erl +S Schedulers:SchedulerOnline • defaults to logical processors configured • Balancing workload on multiple processors
  12. 12. SMP Schedulers 图⽚片来源:http://ithelp.ithome.com.tw/articles/10161709
  13. 13. Workload Balancing • Check workload periodically by one scheduler • Default period: 2000*2000 reductions. • erl_process.c: • #define ERTS_RUNQ_CHECK_BALANCE_REDS_PER_SCHED (2000*CONTEXT_REDS) • check_balance in erl_process.c • During a period: • work sharing/stealing • determines the number of active schedulers for the next period based on the load of the current period
  14. 14. Number of schedulers
  15. 15. Next active schedulers
  16. 16. Work migration
  17. 17. Memory Management http://erlang.org/doc/man/erts_alloc.html
  18. 18. Garbage Collection • Process heap: copying generational garbage collector. • 共享 Binary: 引⽤用计数 • https://www.erlang-solutions.com/blog/ erlang-19-0-garbage-collector.html
  19. 19. GC
  20. 20. Control GC • erl +h min_heap_size • spawn min_heap_size/min_bin_vheap_size • :erlang.garbage_collect() • Statistics: • :erlang.process_info(pid, :garbage_collection) • :erlang.system_info(:garbage_collection)
  21. 21. 参考资料料 • http://www.diva-portal.org/smash/get/diva2:392243/ FULLTEXT01.pdf • https://www.erlang-solutions.com/blog/erlang-19-0-garbage- collector.html • https://hamidreza-s.github.io/erlang/scheduling/real-time/ preemptive/migration/2016/02/09/erlang-scheduler-details.html • http://www.cnblogs.com/me-sa/archive/2011/11/13/erlang0014.html • https://www.zhihu.com/question/24732869

×