O'Reilly logo

Crafting Rails 4 Applications, 2nd Edition by José Valim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Streaming with Rack

Although we could improve our metrics application to show beautiful graphics and reports, we will instead provide a way to export the data stored in the database so it can be rendered in a third-party service or tool.

The default approach to send data from the server to the client in Rails is to use the send_data method. However, this approach requires us to generate upfront the whole string we want to send, which may take time and require a lot of memory as we store more metrics in our database. To solve this problem, we’ll stream data, allowing us to send data to the client in chunks without allocating a huge blob of memory.

In Chapter 5, Streaming Server Events to Clients Asynchronously, we used Rails’s live-streaming ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required