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

event loops in practice
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Event Loops in Practice

July 19, 2017

slide-2
SLIDE 2

Review Quiz

slide-3
SLIDE 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
slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 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

slide-8
SLIDE 8

Done!

slide-9
SLIDE 9

Contributing to Open Source Projects

slide-10
SLIDE 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"

slide-11
SLIDE 11

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

slide-12
SLIDE 12

Using Event Loops

slide-13
SLIDE 13

Event Loop Review

  • Single Threaded
  • Handle different events on waiting events
  • Inversion of control style
slide-14
SLIDE 14

Comparison

  • Few changes to

existing code

  • Possible performance

increase (vs event loop)

  • Applicable to most…

applications

  • Avoids concurrency

related correctness issues

  • Avoids deadlocks
  • Efficient memory use
  • Not always applicable

Threads Event Loops

slide-15
SLIDE 15

Conceptual Event Loop

  • Based on `select`, `kqueue`, `epoll`
  • Applications use these to register for call backs
  • Single thread, single call stack
slide-16
SLIDE 16

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

slide-17
SLIDE 17

Event Loop Warnings

  • Turns must be fast
  • Turns can never block
  • Long tasks will need
  • Threads
  • Subprocesses
  • Network / micro-services
slide-18
SLIDE 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
slide-19
SLIDE 19

event-loop/{AsyncServer}.java –>

slide-20
SLIDE 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
slide-21
SLIDE 21