dlsecyx pgroammr (dyslexic programmer - cool stuff for scaling)

48
Dlsiecyx Pgroeammr The cool stuff for scaling

Upload: gleicon-moraes

Post on 16-Apr-2017

8.517 views

Category:

Technology


0 download

TRANSCRIPT

Dlsiecyx Pgroeammr

The cool stuff for scaling

Required Listening

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

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.)"

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

Scalability, not Performance

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)

Wait, Wat ?

Sequential Blocking Example

Ruby

Python

URL Fetch Benchmark

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

Python and Twisted

Python/Twisted

Python/Twisted - Verbose and Inlined

Python/Twisted - Generators

Python/Twisted - Deferreds

Python/Twisted - Callbacks

Python/Twisted - Inline Callbacks

Python and GEvent

Python/gevent

Python/gevent - monkey patch

Python/gevent - join the greenlets

Ruby and EventMachine

Ruby/EventMachine

Ruby/EventMachine - Generators

Ruby/EventMachine - Deferreds

Ruby/EventMachine - Callbacks

Ruby/EventMachine/EM-Synchrony - Fiber based

Node.js

Node.js

Node.js - Creating and ending the Request

Node.js - Event handlers

Intermission: Erlang

Erlang

Erlang - Spawning a process to each URL

Erlang - Single URL download

Reminder of what we wanted to do

Ruby

Python

Architectural building blocks

Decoupling db writes with Message Queues

Coupled comment

Uncoupled comment - producer

Uncoupled comment - consumer

Cache

HTML processing - no cache

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

HTML processing - Cached

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

Thanks

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

@[email protected]