views:

59

answers:

2

I have some heavy perfomance issues with Passenger and ajax calls. It seems like every time I do an ajax call, a new ruby instance is started instead of using the one that responded to the original page request, making it really slow. The fact that multiple ajax requests can be made in just a few seconds doesn't make the situation better.

The action I am calling is in itself quite slow (it generates a PDF, which usually takes 5-10 seconds), but when called through Ajax, the response time is 1-3 minutes! This poses no problem in my development environment, as I am using a single mongrel instance, but Passenger really has trouble here.

I have tried the Apache/Passenger options provided for this SO question, but with no luck.

Anyone who has experienced similar issues and found a workaround?

A: 

When are you firing the AJAX request? Perhaps it is overlapping with the page load?

It might help to wait until the DOM load event before firing the AJAX request.

Shtééf
The request is fired when the user clicks a button. It is slow no matter if the whole page has been loaded or not. As far as I have understood, the bottleneck is that Passenger starts a new ruby instance for each request. Perhaps I should limit the maximum number of worker threads.
Daniel Abrahamsson
A: 

Actually, the answer lies in the question. The problem lies in that Passenger spawns to many new application instances, instead of using the existing pool. So one way to fix this is to set the maximum number of workers:

PassengerMaxPoolSize 2

This solved my problem, and cut the response time to 10%-25% of the original time.

Update

An even better approach is to limit that the number of workers that may handle a single user. This is the approach that I ended up using:

PassengerMaxInstancesPerApp 1
Daniel Abrahamsson
Are you sure that is a good approach? As your user grows you would want to increase the pool size also.
jpartogi
It is an internal system with few simultaneous users, but with high interaction from these users. If this poses a problem, I will look into stacking the requests and increase the pool size.
Daniel Abrahamsson