AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is...
Transcript of AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is...
![Page 1: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/1.jpg)
AP4RAsynchronous Processing for Ruby
![Page 2: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/2.jpg)
what is it?
• asynchronous job processor
• you mean like backgroundrb?
• yes! and no!
![Page 3: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/3.jpg)
features
• async. message queueing and dispatching
• reliable messaging
• load balancing
![Page 4: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/4.jpg)
the specials
• async. logic without extra workers
• an async. task is just another controller action
• supports http post, soap, xmlrpc
![Page 5: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/5.jpg)
delivery
• immediately through drb
• store and forward
• first store message (through activerecord)
• then deliver
• ensures guaranteed delivery
![Page 6: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/6.jpg)
message storage
• file based
• database (for now only mysql)
![Page 7: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/7.jpg)
scenarios
• mass mailings
• cache sweeping
• search index rebuilding
• feed aggregation
![Page 8: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/8.jpg)
setup
• ap4r is a gem
• and a plugin
• setup
• ap4r_setup ap4r_server
• install rails plugin
![Page 9: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/9.jpg)
setup
• ap4r dispatcher runs with mongrel
• checks for messages and dispatches
![Page 10: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/10.jpg)
how it works
Internet
Mongrel/Rails
AP4R
Queue Message
Dispatch
Request
Apache
![Page 11: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/11.jpg)
but what about backgroundrb?
• ap4r is simpler
• integrates more seamlessly with rails
• it can async'ly execute http calls on any http server
![Page 12: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/12.jpg)
but i love backgroundrb!
• what's in the background stays in the background
• no scheduling support
• but backgroundrb doesn’t have reliable scheduling anyway
![Page 13: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/13.jpg)
code!
• immediate delivery
ap4r.async_to( {:controller => ‘search‘, :action => ‘reindex‘},{:id => 12} )
ap4r.async_to( {:url => ‘http://localhost:8080/someServlet’},{:id => 12} )
![Page 14: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/14.jpg)
code!
• store and forwardap4r.transaction doap4r.async_to( {:controller...}, {:id => 12} )
end
![Page 15: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/15.jpg)
code!
• store and forwardap4r.transaction doap4r.async_to( {:controller...}, {:id => 12} )
end
Store in SAF
![Page 16: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/16.jpg)
code!
• store and forwardap4r.transaction doap4r.async_to( {:controller...}, {:id => 12} )
end
Store in SAF
Commit Database, Deliver Message
![Page 17: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/17.jpg)
further reading
• http://www.infoq.com/news/2007/06/messaging-with-ap4r
• http://ap4r.rubyforge.org/wiki/wiki.pl?GettingStarted
• http://rubyforge.org/docman/view.php/1765/1257/AP4R_on_RubyKaigi2007_EN.pdf
![Page 18: AP4R - paperplanes.de · the specials • async. logic without extra workers • an async. task is just another controller action • supports http post, soap, xmlrpc](https://reader033.fdocuments.in/reader033/viewer/2022050508/5f990da4e4dd8e481a32bb97/html5/thumbnails/18.jpg)
thanks!