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.

JS Fest 2019. Артур Торосян. V8 - взгляд на асинхронность и работу с ОС изнутри

26 views

Published on

Асинхронность, тредпул и воркеры: ныряем в libUV и V8, добираемся до ОС и пытаемся разобраться в тонкостях Event Loop в главном треде и в воркерах.

Published in: Education
  • Be the first to comment

  • Be the first to like this

JS Fest 2019. Артур Торосян. V8 - взгляд на асинхронность и работу с ОС изнутри

  1. 1. JAVASCRIPT: from Back-end to Front-end PROFESSIONAL JS CONFERENCE
  2. 2. PROFESSIONAL JS CONFERENCE 5-6 APRIL ‘19 KIEV, UKRAINE Artur Torosian V8 - view on asynchrony and working with the OS from the inside
  3. 3. -V8 -Event Loop -libUV -Threads
  4. 4. GOOGLE V8
  5. 5. EVENT LOOP
  6. 6. Event queue Stuff to do Stuff to do Stuff to do API Stuff to do Stuff to do Stuff to do
  7. 7. Black boxEvent queue Stuff to do Stuff to do Stuff to do Stuff to do Stuff to do Stuff to do API
  8. 8. Event Loop Stuff to do Event queue Stuff to do Stuff to do Stuff to doStuff to do Stuff to do Stuff to do API Black box
  9. 9. Event Loop Stuff to do Event queue Stuff to do Stuff to do Stuff to doStuff to do Stuff to do Stuff to do API Callback queue Black box
  10. 10. Event Loop Stuff to do Event queue Stuff to do Stuff to do Stuff to doStuff to do Stuff to do Stuff to do API Callback queue Callback Black box CallbackCallback Callback CallbackCallback
  11. 11. Event Loop Stuff to do Event queue Stuff to do Stuff to do Stuff to doStuff to do Stuff to do Stuff to do API Callback queue Callback Black box CallbackCallback Callback CallbackCallback
  12. 12. Event Loop Stuff to do Event queue Stuff to do Stuff to do Stuff to do Stuff to do Stuff to doStuff to do API Callback queue Callback Black box CallbackCallback Callback Callback Callback Stuff to do Stuff to do
  13. 13. Black box LIBUV (aka Unicorn Velociraptor Library)
  14. 14. Black box
  15. 15. ufftodo Stufftodo Stuffto do Stufftodo Stuffto do Stufftodo Stuffto do Stufftodo Stuffto do Stufftodo Stuffto do Stufftodo Stuffto Stuffto Stuffto do tufftodo Thread Pool
  16. 16. - fs - crypto - DNS - Zlib
  17. 17. Javascript
  18. 18. Javascript Main Thread C++ object code
  19. 19. Javascript Main Thread C++ object code Stuff to do Threadpool
  20. 20. Threadpool Javascript Main Thread C++ object code Stuff to do Return to JS Stuff to do is processing Stuff is done
  21. 21. Threadpool Javascript Main Thread C++ object code Stuff to do Return to JS Stuff is doneStuff is wrapping Callback
  22. 22. Javascript
  23. 23. Threadpool Javascript Main Thread C++ Return to JS Stuff to do is processing Stuff is done object code Stuff to do Callback Stuff is wrapping
  24. 24. Group 1: Hashes 0 - 3 Time: <800 Group 2: Hashes 4 - 7 Time: <1600 Group 3: Hashes 8 - 9 Time: <2400
  25. 25. Group 1: Hashes 0 - 7 Time: <1200 Group 2: Hashes 8-9 Time: <2000
  26. 26. Network
  27. 27. RequestRequest Request Request Request Request Request Request Request Request - Node.js v0.8 - Ubuntu 12.04 LTS - Intel Core i7-2600 Quad - 16gb RAM
  28. 28. RequestRequest Request Request Request Request Request Request Request Request - Node.js v0.8 - Ubuntu 12.04 LTS - Intel Core i7-2600 Quad - 16gb RAM Successful handling of 1M requests
  29. 29. https://habr.com/ru/post/123154
  30. 30. Crossplatform
  31. 31. - child_process - cluster - fs
  32. 32. Worker threads
  33. 33. Node.js 5 threads V8 4 threads Event Loop 1 thread 10 threads Thread pool
  34. 34. Node.js 5 threads V8 4 threads Event Loop 1 thread 6 threads Thread pool
  35. 35. Cluster Node.js V8 Event Loop Thread pool
  36. 36. New process will create their own V8 instance, Event Loop and Thread pool. Huge memory usage. Cluster
  37. 37. Threadpool Node.js V8 Event Loop Thread pool
  38. 38. Only for IO - plugins and fs, crypto, dns and zlib modules. Threadpool
  39. 39. Worker threads Node.js V8 Event Loop Thread pool
  40. 40. Worker threads Memory, performance and stuff like that. Do not help with async tasks, helps only with blocking operations.
  41. 41. Javascript Main Thread C++ Threadpool Node
  42. 42. Javascript Main Thread C++ Threadpool Node Javascript Main Thread C++ Threadpool Node Javascript Main Thread C++ Threadpool Node
  43. 43. Javascript Main Thread C++ Threadpool Node
  44. 44. Javascript Main Thread C++ Threadpool Node
  45. 45. Javascript Main Thread C++Worker 1 Worker 2 Node

×