System call calls a PHP script

Hello,

I want to generate some PDFs from my Rails app.
I use a PHP script to generate the PDF, and it works fine.

In my Rails controller, I just have an action that calls :
`#{full_command}`
where full_command is something like "/usr/bin/php generate_pdf.php".

It just works fine.

Now I want to stress test a little my application.
I use this simple ruby script to test my PDF generation :

#!/usr/bin/ruby
10.times do
  `curl http://0.0.0.0:3000/contents/pdf`
end

The result is that only 3 PDFs are generated.

If I use this ruby script :
#!/usr/bin/ruby

10.times do
  `/usr/bin/php generate_pdf.php`
end

Then the 10 PDFs are generated very quickly.

Does anyone have a clue about what I could do for the 10 PDFs being
generated when called in my Rails controller?
I can't realize where the problem is ...

Is this a Mongrel issue (I'm using Rails 2.0 with the Mongrel test environment)?
Does I have to use something like BackgroundRB? (I'd prefer not to).

Thanks in advance for your lights.
Best,
Thomas.

I would guess that this is related to the fact that you fire of 10
requests to your webserver in absolutely no time(under 1ms?). I think
not all your requests are being processed by the server. Try:
#!/usr/bin/ruby
10.times do
  Kernel.sleep(0.1) #in seconds
  `curl http://0.0.0.0:3000/contents/pdf`
end

Thanks for your help.

I would guess that this is related to the fact that you fire of 10
requests to your webserver in absolutely no time(under 1ms?). I think
not all your requests are being processed by the server.

in my development.log, I can see that the 10 requests are processed.

Try:
#!/usr/bin/ruby
10.times do
  Kernel.sleep(0.1) #in seconds
  `curl http://0.0.0.0:3000/contents/pdf`
end

I have to increase the sleep time to 0.8 secs in order to have the 10
PDFs generated.
So if 10 people request the PDF at the same time, they won't have it
generated. :-/

Any idea?

Not sure on what webserver you are testing on, but from your script I
am guessing Webbrick. Which is really only for testing and not for
production. When using Apache/Mongrel you will see vastly increased
response times. And it is the response times you are concerned about.
I dont think you PDF generation script is too slow.

I'm using the Mongrel that ships with Rails 2.0.1, with the DEV environment.
I've tried to put my `#{full_command}` in a BackgroundRB worker, but I
get the same problem ...

I'm a little bit stuck ... :-/

Which version of bdrb? Can you paste the code of your worker?

I downloaded the last version of bdrb from the SVN trunk.
My code in the worker was just a single line :
`#{full_command}` where full_command looks like "/usr/bin/php generate_pdf.php"

Thomas,

I downloaded the last version of bdrb from the SVN trunk.
My code in the worker was just a single line :
`#{full_command}` where full_command looks like "/usr/bin/php generate_pdf.php"

You need to specify full path to generate_pdf.php, that will solve the problem.