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.
12. 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
16. 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
17. 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
18. 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
19. 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;
}
20. 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
31. 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
32. Hurray, we can write all the new advanced
features in our favorite language ..
33. Ruby makes life easier for …
Instrumentation
Messaging
Analyzer
Interacting with the Database
Admin Panel (It’s a Rails Application!)
34.
35.
36. 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
39. 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 38 – Lion By auburnxc