Successfully reported this slideshow.
Your SlideShare is downloading. ×

Are your v8 garbage collection logs speaking to you?Joyee Cheung -Alibaba Cloud(Alibaba Group)

Are your v8 garbage collection logs speaking to you?Joyee Cheung -Alibaba Cloud(Alibaba Group)

Download to read offline

In this talk, Joyee will talk about alinode's experiences in analyzing the V8 garbage collection logs and diagnosing performance problems caused by V8 GC pauses and memory leaks.

In this talk, Joyee will talk about alinode's experiences in analyzing the V8 garbage collection logs and diagnosing performance problems caused by V8 GC pauses and memory leaks.

More Related Content

More from NodejsFoundation

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Are your v8 garbage collection logs speaking to you?Joyee Cheung -Alibaba Cloud(Alibaba Group)

  1. 1. Are Your V8 Garbage Collection Logs Speaking to You? Joyee Cheung, Alibaba Cloud
  2. 2. What Prompted us to Look into them Node.js at Alibaba
  3. 3. What Prompted Us to Look Into Them Why GC Logs? v Java is the mainstream at Alibaba v Chose Node.js for productivity, but it’s meaningless without availability v Usually not the bottleneck, but with a huge traffic, every optimization counts v Garbage collection is important in long-running, data-intensive servers v High CPU usage: hurts responsiveness v High memory usage: affects other processes v Memory leaks: misled by developers, crashes the process(OOM) v Java developers know their VM and its GC v … v More about Node.js at Alibaba v https://www.linux.com/blog/can-nodejs-scale-ask-team-alibaba
  4. 4. What Prompted Us to Look Into Them Why GC Logs? v Tools from V8/Chromium are more about optimizing frontend applications CPU profiles are more about function calls, less about objects v Heap snapshots and timelines are more about allocations, less about collections v Lack of high-level overview of the heap, too much details Hard to use in staging/production environment
  5. 5. What Prompted Us to Look Into Them Why GC Logs? v V8 provides garbage collection logs v Not documented, not available in the devtools, need to use command line args v Higher-level than heap profiles, lower-level than the number of memory usuage v Help verify the fixes by displaying patterns of GC v Not silver bullet, but nice to have v This talk is based on the versions of V8 used by Node v4 & v6 LTS v LTS plan stablizes the V8 versions for each LTS and its GC logs
  6. 6. An Introduction to V8 GC What is Garbage Collection
  7. 7. An Introduction to V8 GC How Most GCs are triggered
  8. 8. An Introduction to V8 GC Stop-The-World, Parallel, Concurrent GC
  9. 9. An Introduction to V8 GC Generational GC
  10. 10. An Introduction to V8 GC Heap Organization
  11. 11. An Introduction to V8 GC Heap Limits(Default) v deps/v8/src/heap/heap.h: Heap::Heap() 16MB 1MB 1.4GB 0.7GB 512MB v Can be configured via command line arguments v --max_old_space_size, --max_semi_space_size, --max_executable_space_size
  12. 12. An Introduction to V8 GC New Generation – Scavenge GC
  13. 13. An Introduction to V8 GC Old Generation – Mark-Sweep/Compact GC
  14. 14. An Introduction to V8 GC GC Pauses in V8
  15. 15. How to Get The GC Logs v Plenty of options (node --v8-options| grep gc) v We’ll be focusing on v --trace_gc v Print a line briefly describing when, how, what and why for each GC v --trace_gc_verbose v Combined with --trace_gc, summarizes about each space and the heap after each GC v --trace_gc_nvp v Print name-value pairs describing how each step of GC goes v In case you do want to read the code v deps/v8/src/heap, start with gc-tracer.cc
  16. 16. How to Read The GC Logs v --trace_gc WHERE: [PID:Isolate] WHEN: Time since the process has started WHAT: Type of GC HOW MUCH: Size of all objects(Size of memory allocated from OS) HOW LONG: GC pause/Time spent on external memory WHY
  17. 17. How to Read The GC Logs v --trace_gc_verbose && --trace_gc Memory V8 allocated from the OS All memory reserved for this space (inside dedicated pages) Maintained by external C++ code Adjust heap growing factor and the allocation limit that triggers the next incremental marking
  18. 18. How to Read The GC Logs v --trace_gc_nvp ms=Mark-Sweep, s=Scavenge
  19. 19. What We’ve Found v Tons of Scavenge GC in New Space eating up the CPU v Cache misses caused by inappropriate caching strategies v Excessive deep clones/object merging v Large Object Space keeps growing v Serialization/deserialization of huge RPC payload v Code Space keeps growing v Bugs in templating engines v Old Space keeps growing v Closures in long connections
  20. 20. Tools v Our parser v Up on NPM v For people who already have applications running in production https://github.com/aliyun-node/v8-gc-log-parser http://alinode.aliyun.com/blog (translation coming soon) Visualization coming soon!
  21. 21. Tools v --trace_gc_object_stats v Feed the output to https://mlippautz.github.io/v8-heap-stats/ v Requires Node >= v7 v More about the memory usuage, less about GC v --track_gc_object_stats v Combined with --log_timer_events, writes a log file to disk v Can be viewed with chrome://tracing (Incomplete???) v Pending PR: https://github.com/nodejs/node/pull/9304
  22. 22. THANKS Twitter/Github: @joyeecheung joyeec9h3@gmail.com https://alinode.aliyun.com
  23. 23. An Introduction to V8 GC Accurate GC

×