Lets build-ruby-app-server: Vineet tyagi


Published on

Would you like to know how to build an application server from scratch? This talk would provide an insight to the thought process and the key decisions made while building WebROaR from grounds up using C & Ruby.

What enables this server to deliver high performance and also offer a rich bouquet of integrated features like Analytics, Exception Notifications etc? If gaining knowledge about design of a good software product interests you, do join us for this interactive session.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lets build-ruby-app-server: Vineet tyagi

  1. 1. Let’s build a Ruby Application Server Team WebROaR
  2. 2. How do ‘you’ visualize an ‘Application Server’?
  3. 3. Or it could be like this …
  4. 4. Let’s define the specs
  5. 5. Rack Compliant Run all Ruby Web Applications
  6. 6. And also ..  Provide run time performance numbers of the deployed applications  Report exceptions
  7. 7. Love to have …  Maximum performance  Simplicity
  8. 8. Let’s start building it …
  9. 9. What does the server need to do? Accept client connection Parse HTTP request Hand it over to the ruby web framework Send its response back to the client
  10. 10. Network Server Design Evented vs Threaded
  11. 11. Event Based I/O Libraries  libev (Written in C)  EventMachine (Ruby Module + Extension Library written in C++)
  12. 12. HTTP Parser Mongrel’s Ragel Based Parser (written in C) is ‘awesome’
  13. 13. Server Tasks Options Accept client connection libev/EventMachine Parse HTTP request Mongrel’s Ragel based Parser Hand it over to the ruby web ? framework Send its response back to the libev/EventMachine client
  14. 14. More awesomeness - Libebb  Lightweight HTTP Library for C  libev + Mongrel’s Ragel based Parser  Implements HTTP/1.1 Grammar  Supports persistent, pipelined & chunked requests  Rejects invalid and malicious requests
  15. 15. Server Tasks Options Accept client connection libebb Parse HTTP request libebb Hand it over to the ruby web ? framework Send its response back to the libebb client
  16. 16. Embedded Ruby Interpreter #include <ruby.h> int main(int argc, char **argv) { int state = 0; ruby_init(); ruby_script("c-executable-name"); ruby_init_loadpath(); //Can use rb_gv_set() or rb_iv_set() methods to pass parameters to ruby land rb_protect(RUBY_METHOD_FUNC(rb_require), (VALUE)"path-to-ruby-script", &state); if(state != 0) { // Exception Handling Code return -1; } //Can use rub_funcall() to invoke methods in the ruby land return 0; }
  17. 17. Server Tasks Options Accept client connection libebb Parse HTTP request libebb Hand it over to the ruby web Embedded Ruby Interpreter framework Send its response back to the libebb client
  18. 18. Hola, we got a basic application server ready!
  19. 19. The Server – First Cut HTTP Request Rack Web Application libebb Ruby Interpreter Response
  20. 20. But it only processes one request at a time ..
  21. 21. Let’s split up the server code and create more ruby processing instances & static file renderers (‘workers’)
  22. 22. The more powerful server version … Rack Web Application libev Asynchronous Ruby Interpreter Non-blocking I/O Worker #1 HTTP Request Rack Web Application SCGI libev libebb libev Ruby Interpreter Response Worker #2 Head libev Static Files Renderer Worker #n
  23. 23. Server can handle (very) high load with this architecture
  24. 24. Let’s capture data for each request being processed …
  25. 25. The Server – Current Architecture Message Queue Analyzer Admin Panel Daemon DB Request Analytics Data & Exception Notifications Conf File HTTP Request Worker #1 Head Worker #n Response
  26. 26. Hurray, we can write all the new advanced features in our favorite language .. 
  27. 27. Ruby makes life easier for …  Instrumentation  Messaging  Analyzer  Interacting with the Database  Admin Panel (It’s a Rails Application!)
  28. 28. Takeaways  Use the best tool for the job  C – Network I/O, Ruby – Advanced Features  Do not reinvent the wheel. Use tried and tested libraries
  29. 29. Check it out WebROaR – http://webroar.in
  30. 30. More Questions?
  31. 31. Photo Credits All photographs used in this presentation are licensed under Creative Commons  Slide 3 – Stone House By Jsome1  Slide 5, 34 – Our House By Lee Coursey  Slide 11 – Willow Lane Construction By Lee Coursey  Slide 22 – Construction of our House – Framing By Lee Coursey  Slide 27 – Dead Lift By scarndp  Slide 29 – Willow Lane Construction By Lee Coursey  Slide 35 – Very Happy By Chris Winters  Slide 37 – Lion By auburnxc