Page 167 of 171

Juggernaut Rails Chat – part I – What is and how to install Juggernaut

Today we will start creating our own Rails flash socket based chat engine.

What is Juggernaut?

The Juggernaut plugin for Ruby on Rails aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client. In other words your app can have a real time connection to the server with the advantage of instant updates. Although the obvious use of this is for chat, the most exciting prospect is collaborative cms and wikis. Now you won't need to make requests every 1-2 seconds to check for data. Data will be send directly to you!

Lets assume - we have 60 chat users. Each one checks every 0.5 second for new data. They don't write anything - just sit there, but there will always be 120 requests per second even when nothing is happening. And that's the place where Juggernaut magic helps

Installation

This tutorial is for *nix users - never tried to run it on Windows.

What we need?

We need to install some additional gems:

gem install json
gem install eventmachine

And of course Juggernaut:

sudo gem install juggernaut

And that’s all for now. Next time we will start building our small chat.

Tutorial parts:

  1. Juggernaut Rails Chat – part I (what is and how to install Juggernaut)
  2. Juggernaut Rails Chat – part II (design)
  3. Juggernaut Rails Chat – part III (registration and authentication)
  4. Juggernaut Rails Chat – część IV (zarządzanie pokojami)
  5. Juggernaut Rails Chat – część V (łączenie użytkowników z pokojami)
  6. Juggernaut Rails Chat – część VI (odpalamy Juggernaut i nasz chat)
  7. Juggernaut Rails Chat – część VII (emotikonki i dźwięk)

Why I have decided to quit using Cookie Jar

Recently I've been developing some JS stuff using Cookie Jar (source). Everything went great and Cookie Jar got along even with IE :) However, cookie jar cookie happened to grow and grow to fast.

Cookie Jar stores parts of Cookie as a key-value pair [key][value], so if you have a lot of small stuff - the cookie will be two times bigger than the data stored in it. Example:

[m][5] - number of chars: 2 (m,5); total amount: 6 ; waste 4 chars.

Phi, nothing special you say. Only 4 characters. In such a simple example maybe but if you store a lot of stuff, waste will be much bigger.

There has been additional problem. Some characters where stored as HTML entities. I don't know why - I've stored in cookie jar only numbers ;)

So, my cookie grew and grew more rapidly. And along with this - something else happened. Performance started to be really bad. Everything worked really slow. Can't say whether or not it is only Cookie Jar fault, but after switching to my own cookie engine, performance got better.

When I've been using Cookie Jar - "setting up" GUI took some time, so users felt this delay. Currently all init stuff goes really fast and none of them feels this.

Whether or not use Cookie Jar?

Cookie jar is convenient and easy to use. If you don't store whole bunch of small stuff in it and you don't care so much about performance - definitely you should use it. However if you need something really fast and thin - you should write your own dedicated cookie handler.

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑