Ruby loves Unix: Applying beautiful Unix idioms to build a Ruby prefork server

Ruby loves Unix: Applying beautiful Unix idioms to build a Ruby prefork server

The Unix programming model has existed for more than 40 years now. Unix programming techniques and principles have transcended programming languages and frameworks du jour. Also, Ruby was built for unix hacking. Implementing unix system calls in its standard library was the best perlism Ruby adopted.

Learning Unix programming and its idioms will make you a better Ruby programmer. Your ruby programs will be friendly citizens on your *nix server making them easy to administer. You will be able to daemonize your code at will. Your concurrent ruby code will be easy to grok and debug. You will have deeper understanding into the inner working of popular tools like the Resque job scheduler and
the Unicorn web server.

This talk is divided into two parts. The first part will be a dive into the basic building block of the unix programming model: processes. We will learn the application of the myriad unix system calls such as kill(2), fork(2), execve(2), pipe(2) and friends to our processes and understand various important idioms.

The next part will involve using the knowledge we've gained to build a Ruby preforking server. Our daemon will follow the classical master/worker prefork model wherein the master will fork and monitor its children and use the operating system to load balance work amongst available children. Our daemon will demonstrate classical unix idioms like daemonizing via double fork(2), administration via signals, IPC via signals and pipes,
concurrency via fork(2) and many more.

8b37c3f0f438c6844468ef43a188d878?s=128

Sahil Muthoo

June 23, 2013
Tweet