Your SlideShare is downloading. ×
0
Performance vs Scalability <ul><li>Blocking or non-blocking code, code complexity and architectural blocks to avoid code c...
$whoami <ul><li>work:  http://locaweb.com </li></ul><ul><li>site:  http://7co.cc </li></ul><ul><li>blog:  http://zenmachin...
Required Listening “ But your new shoes are worn at the heels  and your suntan does rapidly peel and your wise men don't k...
Objective <ul><li>To discuss how scalability sometimes get confused with performance when speaking about non-blocking I/O ...
Basics <ul><ul><li>Asynchronous I/O - Posix aio_* </li></ul></ul><ul><ul><li>Non-Blocking I/O - Select, Poll, EPoll, Kqueu...
Scalability, not performance
Scalability, not performance <ul><ul><li>Performance:  same work with less resources </li></ul></ul><ul><ul><li>Scalabilit...
JAVA concurrency in practice
Blocking code example - Download a list of URLs Ruby Python
Benchmark <ul><li>Compare blocking and non-blocking Ruby code to download a list of URLs </li></ul><ul><li>A naive example...
Benchmark - Blocking
Benchmark  –  Blocking + Threads
Benchmark - Non-Blocking (Eventmachine based)
Benchmark - Results <ul><li>2 urls </li></ul><ul><li>Blocking I/O:  0m4.061s </li></ul><ul><li>Blocking I/O + Threads:  0m...
Python and Twisted
Python and Twisted  –  callback styles Explicit Inline
Python and Twisted  –  Generators Generators
Python and Twisted  –  Deferreds Not Deferreds Deferreds
Python and Twisted  –  Callbacks Callbacks
Python and Twisted  –  Inline callbacks Results from getPage
Python and GEvent Monkey patch the socket module
Python and GEvent C reate and start greenlets
Ruby and EventMachine
Ruby and EventMachine - Generators Generator
Ruby and EventMachine - Deferreds Sort of deferred
Ruby and EventMachine - Callbacks Success and error callbacks
Ruby, EventMachine and EM-Synchrony
Ruby, EventMachine and EM-Synchrony Inline results
Node.js
Node.js  –  Creating and ending the requests Start requests End requests
Node.js  –  Events handlers and callbacks Response event
Erlang
Erlang  –  Spawning one download process per url
A reminder of what we wanted to do
Blocking code example - Download a list of URLs Ruby Python
Architectural building blocks
M e ssage Queues  –  decoupling downloads
M e ssage Queues  –  decoupling db writes on a webservice
Coupled comments webservice Receive and  write to db
Message Queue  –  Comment producer Receive and  write to queue, release connection
Message Queue  –  Comment consumer Take from queue and write to db
Cache
No cache  –  code from http://github.com/gleicon/vuvuzelr
Cache  –  code from http://github.com/gleicon/vuvuzelr Check if it ’ s on cache Return if it is Feed the cache and set exp...
Redis <ul><li>Key/Value store </li></ul><ul><li>Key is a string, Value can be string, hash, list, set, scored set </li></u...
Q & A
Thanks !
Upcoming SlideShare
Loading in...5
×

OSCon - Performance vs Scalability

8,869

Published on

Slides for my talk at OSCon 2011 on scalability vs performance, frameworks for non-blocking I/O and message queues.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,869
On Slideshare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
66
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "OSCon - Performance vs Scalability"

  1. 1. Performance vs Scalability <ul><li>Blocking or non-blocking code, code complexity and architectural blocks to avoid code complexity </li></ul>
  2. 2. $whoami <ul><li>work: http://locaweb.com </li></ul><ul><li>site: http://7co.cc </li></ul><ul><li>blog: http://zenmachine.wordpress.com </li></ul><ul><li>code: http://github.com/gleicon </li></ul><ul><li>RestMQ: http://restmq.com </li></ul><ul><li>twitter: @gleicon </li></ul>
  3. 3. Required Listening “ But your new shoes are worn at the heels and your suntan does rapidly peel and your wise men don't know how it feels to be thick as a brick. ”
  4. 4. Objective <ul><li>To discuss how scalability sometimes get confused with performance when speaking about non-blocking I/O </li></ul><ul><li>To show how most of languages have frameworks to deal with non-blocking I/O </li></ul><ul><li>Examine an example in different languages and the basic blocks of these frameworks </li></ul><ul><li>Discuss that this programming model is mandatory, not even migrate from Blocking to non-blocking I/O is needed for most cases. The best solution may not lie in code complexity, but in the right architecture. </li></ul><ul><li>Discuss a bit about Message Queues, Cache and Redis </li></ul>
  5. 5. Basics <ul><ul><li>Asynchronous I/O - Posix aio_* </li></ul></ul><ul><ul><li>Non-Blocking I/O - Select, Poll, EPoll, Kqueue </li></ul></ul><ul><ul><li>Reactor - Pattern for multiplexing I/O </li></ul></ul><ul><ul><li>Future Programming – Generators  and Deferreds </li></ul></ul><ul><ul><li>Event Emitters  </li></ul></ul><ul><ul><li>The c10k problem - http://www.kegel.com/c10k.html </li></ul></ul>
  6. 6. Scalability, not performance
  7. 7. Scalability, not performance <ul><ul><li>Performance: same work with less resources </li></ul></ul><ul><ul><li>Scalability: more work with added resources </li></ul></ul><ul><ul><li>Scientific measures for performance: How much and How fast </li></ul></ul><ul><ul><li>Tricks to improve performance can hurt scalability. </li></ul></ul><ul><ul><li>Non-Blocking I/O is not an optimization for Performance </li></ul></ul><ul><ul><li>The time spent waiting for an external resource can be used to other tasks, given a known introduced complexity in the code. </li></ul></ul><ul><ul><li>Most of time architectural changes can avoid deeper code changes </li></ul></ul><ul><li>(1,2,3,4 - Goetz et al, Java Concurrency in Practice)  </li></ul><ul><li>(5,6,7 - Lucindo, R. http://slidesha.re/aYz4Mk, wording on 6 is mine) </li></ul>
  8. 8. JAVA concurrency in practice
  9. 9. Blocking code example - Download a list of URLs Ruby Python
  10. 10. Benchmark <ul><li>Compare blocking and non-blocking Ruby code to download a list of URLs </li></ul><ul><li>A naive example to examine the effects of both paradigms on the final code </li></ul><ul><li>The ‘ algorithm ’ to download an URL is (should be) the same in both versions </li></ul><ul><li>If we had more cores, or more powerful cores, it should not affect the performance of a single download (I/O bound operation) </li></ul>
  11. 11. Benchmark - Blocking
  12. 12. Benchmark – Blocking + Threads
  13. 13. Benchmark - Non-Blocking (Eventmachine based)
  14. 14. Benchmark - Results <ul><li>2 urls </li></ul><ul><li>Blocking I/O:  0m4.061s </li></ul><ul><li>Blocking I/O + Threads: 0m2.914s </li></ul><ul><li>Non-blocking I/O:  0m1.027s </li></ul><ul><li>100 urls </li></ul><ul><li>Blocking I/O:  2m46.769s </li></ul><ul><li>Blocking I/O + Threads: 0m33.722s </li></ul><ul><li>Non-blocking I/O:  0m11.495s </li></ul>
  15. 15. Python and Twisted
  16. 16. Python and Twisted – callback styles Explicit Inline
  17. 17. Python and Twisted – Generators Generators
  18. 18. Python and Twisted – Deferreds Not Deferreds Deferreds
  19. 19. Python and Twisted – Callbacks Callbacks
  20. 20. Python and Twisted – Inline callbacks Results from getPage
  21. 21. Python and GEvent Monkey patch the socket module
  22. 22. Python and GEvent C reate and start greenlets
  23. 23. Ruby and EventMachine
  24. 24. Ruby and EventMachine - Generators Generator
  25. 25. Ruby and EventMachine - Deferreds Sort of deferred
  26. 26. Ruby and EventMachine - Callbacks Success and error callbacks
  27. 27. Ruby, EventMachine and EM-Synchrony
  28. 28. Ruby, EventMachine and EM-Synchrony Inline results
  29. 29. Node.js
  30. 30. Node.js – Creating and ending the requests Start requests End requests
  31. 31. Node.js – Events handlers and callbacks Response event
  32. 32. Erlang
  33. 33. Erlang – Spawning one download process per url
  34. 34. A reminder of what we wanted to do
  35. 35. Blocking code example - Download a list of URLs Ruby Python
  36. 36. Architectural building blocks
  37. 37. M e ssage Queues – decoupling downloads
  38. 38. M e ssage Queues – decoupling db writes on a webservice
  39. 39. Coupled comments webservice Receive and write to db
  40. 40. Message Queue – Comment producer Receive and write to queue, release connection
  41. 41. Message Queue – Comment consumer Take from queue and write to db
  42. 42. Cache
  43. 43. No cache – code from http://github.com/gleicon/vuvuzelr
  44. 44. Cache – code from http://github.com/gleicon/vuvuzelr Check if it ’ s on cache Return if it is Feed the cache and set expiration
  45. 45. Redis <ul><li>Key/Value store </li></ul><ul><li>Key is a string, Value can be string, hash, list, set, scored set </li></ul><ul><li>Atomic operations </li></ul><ul><li>Publish/Subscription channels </li></ul><ul><li>Set/Scored Sets operations (union, diff, intersection) </li></ul><ul><li>UUID Generator, Distributed Cache, Message Queue (RestMQ, Resque), Serialized object storage, throttle control and more at http://rediscookbook.org/ </li></ul>
  46. 46. Q & A
  47. 47. Thanks !
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×