event loops in practice
play

Event Loops in Practice July 19, 2017 Review Quiz Which of these - PowerPoint PPT Presentation

Event Loops in Practice July 19, 2017 Review Quiz Which of these is not a common method for speeding up an application? A. Threading B. Forking / Subprocesses C. Compression / Gzipping D. Event Loops / Async programming What is a benefit


  1. Event Loops in Practice July 19, 2017

  2. Review Quiz

  3. Which of these is not a common method for speeding up an application? A. Threading B. Forking / Subprocesses C. Compression / Gzipping D. Event Loops / Async programming

  4. What is a benefit of threading? A. When one thread is waiting for IO, another thread can be doing work B. When one thread is waiting for IO, other threads can speed up that IO operation C. When one thread is executing, another thread can be doing garbage collection D. When one thread is executing, another thread can preserve memory

  5. What is a disadvantage of threading? A. Threads can be confusing for the kernel scheduler, causing segfaults B. Threads take up too much memory to speed up single threaded programs C. Multiple threads can modify the same memory, causing consistency errors D. Threads can operate too quickly for some processors, harming hardware

  6. What is an advantage of event loops / async programming? A. Event loops allow multiple parts of your application to execute simultaneously, increasing responsiveness B. Event loops efficiently use a single thread, blending responsiveness without the danger of threading C. Event loops increase the efficiency of the language's looping operators (for, while, do) increasing speed D. Event loops execute parts of a program on the GPU, using more hardware effectively

  7. What is an disadvantage of event loops / async programming? A. Event loops allocate too much stack memory, which can cause programs to terminate B. Event loops use too many threads, which can interfere with other programs running on the system C. Event loops require writing programs in a different, "inside out" way, which can be difficult to learn D. Event loops can cause different parts of your program to corrupt program variables

  8. Done!

  9. Contributing to Open Source Projects

  10. Github Example • Fork the project 
 Create a clone of the project in git • Create a branch 
 Isolate your changes from irrelevant changes • Fix the problem 
 Make the changes to the project locally • Suggest the code 
 Ask the main project with a "pull request"

  11. https://github.com/snyderp/petes-problem-repo

  12. Using Event Loops

  13. Event Loop Review • Single Threaded • Handle different events on waiting events • Inversion of control style

  14. Comparison Threads Event Loops • Few changes to • Avoids concurrency related correctness existing code issues • Possible performance • Avoids deadlocks increase (vs event loop) • Efficient memory use • Applicable to most… applications • Not always applicable

  15. Conceptual Event Loop • Based on `select`, `kqueue`, `epoll` • Applications use these to register for call backs • Single thread, single call stack

  16. event-loop/{EventLoop, ReadAsync}.java –>

  17. Event Loop Warnings • Turns must be fast • Turns can never block • Long tasks will need • Threads • Subprocesses • Network / micro-services

  18. If you block… • Your function call will take a long time • Event loop will freeze for you to finish • Your whole application will freeze

  19. event-loop/{AsyncServer}.java –>

  20. Conclusion • Event loops are great • Performance benefits of threads w/o the danger • Even better if program is IO bound • Event loops are fragile • Any blocking call back can bring the system down • Event loops are everywhere

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend