Top Banner
Dlsiecyx Pgroeammr The cool stuff for scaling
48

Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Apr 16, 2017

Download

Technology

Gleicon Moraes
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Dlsiecyx Pgroeammr

The cool stuff for scaling

Page 2: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Required Listening

Page 3: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Disclaimer about me

- I like both Ruby and Python, but I dislike the generator/deferred model they implement for non-blocking I/O

- I think node.js beats them because its better wrapped, as EM synchrony does to EM and gevent for python.

- I don't think this 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. Maybe the right architecture.

- I like Erlang, the actor/message passing model and pattern matching. Way more. And I like message queues. Specially this one: http://www.restmq.com

Page 4: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Disclaimer about dyslexia

From wikipedia (http://en.wikipedia.org/wiki/Dyslexia):

"... Many students reach higher education before they encounter the threshold at which they are no longer able to compensate for their learning weaknesses.

One common misconception about dyslexia is that dyslexic readers write words backwards or move letters around when reading. In fact, this only occurs in a very small population of dyslexic readers. Dyslexic people are better identified by writing that does not seem to match their level of intelligence from prior observations. Additionally, dyslexic people often substitute similar-looking, but unrelated, words in place of the ones intended (what/want, say/saw, help/held, run/fun, fell/fall, to/too, etc.)"

Page 5: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Basics

Asynchronous I/O - Posix aio_*Non-Blocking I/OSelect, Poll, EPoll, KQueueEvented I/O - Abstraction over any I/O ModelReactor - Pattern for multiplexing I/OFuture ProgrammingGenerator Deferred Event Emitters The c10k problem - http://www.kegel.com/c10k.html

Page 6: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Scalability, not Performance

Page 7: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Scalability, not Performance

1. Performance: same work with less effort2. Scalability: more work with more resources3. Scientific measures for performance: How much and How fast4. Tricks to improve performance can hurt scalability. e.g:

Map/Reduce is scalable, not fast (not suited for real time queries)

5. Non-Blocking I/O is not an optimization for Performance6. The time spent waiting for an external resource can be used

to other tasks, given a known introduced complexity in the code.

7. Most of time architectural changes can avoid deeper code changes

(1,2,3,4 - Goetz et al, Java Concurrency in Practice, M/R example is mine) (5,6,7 - Lucindo, R. http://slidesha.re/aYz4Mk, wording on 6 is mine)

Page 8: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Wait, Wat ?

Page 9: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Sequential Blocking Example

Page 10: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby

Python

Page 11: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

URL Fetch Benchmark

Page 12: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

URL Fetch Benchmark

2 urlsSequential blocking I/O using ruby: 0m3.061sNon-blocking I/O using ruby and Eventmachine: 0m0.795s

28 urlsSequential blocking I/O using ruby: 0m56.014sNon-blocking I/O using ruby and Eventmachine: 0m24.519s

Page 13: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python and Twisted

Page 14: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/Twisted

Page 15: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/Twisted - Verbose and Inlined

Page 16: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/Twisted - Generators

Page 17: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/Twisted - Deferreds

Page 18: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/Twisted - Callbacks

Page 19: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/Twisted - Inline Callbacks

Page 20: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python and GEvent

Page 21: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/gevent

Page 22: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/gevent - monkey patch

Page 23: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Python/gevent - join the greenlets

Page 24: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby and EventMachine

Page 25: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby/EventMachine

Page 26: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby/EventMachine - Generators

Page 27: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby/EventMachine - Deferreds

Page 28: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby/EventMachine - Callbacks

Page 29: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby/EventMachine/EM-Synchrony - Fiber based

Page 30: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Node.js

Page 31: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Node.js

Page 32: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Node.js - Creating and ending the Request

Page 33: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Node.js - Event handlers

Page 34: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Intermission: Erlang

Page 35: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Erlang

Page 36: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Erlang - Spawning a process to each URL

Page 37: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Erlang - Single URL download

Page 38: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Reminder of what we wanted to do

Page 39: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Ruby

Python

Page 40: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Architectural building blocks

Page 41: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Decoupling db writes with Message Queues

Page 42: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Coupled comment

Page 43: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Uncoupled comment - producer

Page 44: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Uncoupled comment - consumer

Page 45: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Cache

Page 46: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

HTML processing - no cache

http://github.com/gleicon/vuvuzelr/proxy_no_cache.rb

Page 47: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

HTML processing - Cached

http://github.com/gleicon/vuvuzelr/proxy.rb

Page 48: Dlsecyx pgroammr (Dyslexic Programmer - cool stuff for scaling)

Thanks

http://zenmachine.wordpress.comhttp://github.com/gleiconhttp://www.7co.cc

@[email protected]