NeverBlock and ActiveRecord, Concurrent DB Access Without Threads
A new neverblock_postgresql activerecord adapter has been released. This new adapter makes it possible for applications using activerecord to utilize multiple connections to do queries in parallel in single threaded applications. This results in much higher performance and better CPU utilization.
What do I need to do?
If you were using the vanilla postgresql adapter you would’ve initialized the connection as follows:
Now, to use NeverBlock all you need to do is:
Note: you must have the pg, neverblock, neverblock-pg and the activerecord-neverblock-postgresql-adapter gems installed
This way the AR library will pick the gem and use neverblock_postgresql instead of the postgresql adapter
Is that all?
To be able to utilize NeverBlock, you need to be running in an EventLoop, namely EventMachine's event loop. Establishing a connection should happen in the EM.run block or in a later event. The other thing is that you need to be running within a fiber, using NeverBlock's FiberPool class. Does it sound confusing? don't worry, soon we will release an end to end solution where you wont worry about any of this to reap all the benefits of NeverBlock.
Example
We benchmarked the new adapter against the vanilla postgresql adapter. This time our workloads consisted of normal AR operations repeated for a 1000 times. We increased the workload by increasing the count and complexities of the queries we ran in each fiber.
Running the work loads against postgresql-adapter vs neverblock-postgresql-adapter

NeverBlock advantage for different workloads

Active Record Connection Scaling With NeverBlock
Testing NeverBlock with different connection counts for slow and fast queries

The benchmarks page has been updated with the NeverBlock::ActiveRecord performance results.
What's next? I think you already guessed it!
