Why does number of hits per second go from 1800 to 20?

i had the following code to ball-park the number of possible hits per
second my macbook can support:

<% t = Time.now %>

Hello#index

Find me in app/views/hello/index.rhtml

<% for i in 1..100 do %>
  <%= Time.now %>
  <%= h @ha %>
  <%= sanitize @ha %>
  <%= u @ha %>
  <%= @ha.to_json %>
  <%= strip_tags @ha %>

  <%= Time.now - t %>

  <%= 1 / (Time.now - t) %>
<% end %>

so the last number is how many page server this page can support in 1
second if it stops right there.

that number is initially about 1800, and then at the end of the loop, it
is just 20.

this program is not so CPU intensive, it seems...  i wonder how come it
drops from 1800 to 20 that quickly?  thanks.

On Apr 22, 5:35 pm, SpringFlowers AutumnMoon <rails-mailing-
[email protected]> wrote:

so the last number is how many page server this page can support in 1
second if it stops right there.

that number is initially about 1800, and then at the end of the loop, it
is just 20.

this program is not so CPU intensive, it seems… i wonder how come it
drops from 1800 to 20 that quickly? thanks.

after the 1st iteration through the loop you have used (aparently)
1/1800 of a second.
having done 100 iterations, you’ve used 1/20th of a second ie aprox
1/1800 * 100. How is it a surprise that doing something 100 times
takes roughly 100 times as long as doing it once.

This “benchmark” is also only testing erb - it is not testing any of
the actioncontroller, routing etc… (you might find ab enough for
your needs(

Fred

Frederick C. wrote:

after the 1st iteration through the loop you have used (aparently)
1/1800 of a second.
having done 100 iterations, you’ve used 1/20th of a second ie aprox
1/1800 * 100. How is it a surprise that doing something 100 times
takes roughly 100 times as long as doing it once.

This “benchmark” is also only testing erb - it is not testing any of
the actioncontroller, routing etc… (you might find ab enough for
your needs(

Fred

hm, i think i am looking for more fixed cost… such as running the loop
1 time, the machine can serve 1800 pages per second and running the loop
100 times, the machine can serve 200 pages per second. so you are
saying that fixed cost is minimal and it is largely just the execution
time? fixed cost involves forking a process, for example… but is it
true that there is no newly created process when a page is served?
thanks.

On Apr 22, 6:49 pm, SpringFlowers AutumnMoon <rails-mailing-
[email protected]> wrote:

Fred

hm, i think i am looking for more fixed cost… such as running the loop
1 time, the machine can serve 1800 pages per second and running the loop
100 times, the machine can serve 200 pages per second. so you are
saying that fixed cost is minimal and it is largely just the execution
time? fixed cost involves forking a process, for example… but is it
true that there is no newly created process when a page is served?
thanks.

there is no process created.
I’m not saying that there is no fixed cost, I’m saying that your test
doesn’t cover a large portion of the fixed cost

Fred

Change this:

<% t = Time.now %>

Hello#index

Find me in app/views/hello/index.rhtml

<% for i in 1..100 do %>
  <%= Time.now %>
  <%= h @ha %>
  <%= sanitize @ha %>
  <%= u @ha %>
  <%= @ha.to_json %>
  <%= strip_tags @ha %>

  <%= Time.now - t %>

  <%= 1 / (Time.now - t) %>
<% end %>

to this:
<% for i in 1…100 do %>
<% t = Time.now %>
<%= h @ha %>
<%= sanitize @ha %>
<%= u @ha %>
<%= @ha.to_json %>
<%= strip_tags @ha %>>
<%= 1 / (Time.now - t) %>
<% end %>

your test is still flawed as the above poster mentioned… but this will
correct the behavior you were previously seeing…

ilan

Ilan B. wrote:

Change this:

<% t = Time.now %>

Hello#index

Find me in app/views/hello/index.rhtml

<% for i in 1..100 do %>
  <%= Time.now %>
  <%= h @ha %>
  <%= sanitize @ha %>
  <%= u @ha %>
  <%= @ha.to_json %>
  <%= strip_tags @ha %>

  <%= Time.now - t %>

  <%= 1 / (Time.now - t) %>
<% end %>

to this:
<% for i in 1…100 do %>
<% t = Time.now %>
<%= h @ha %>
<%= sanitize @ha %>
<%= u @ha %>
<%= @ha.to_json %>
<%= strip_tags @ha %>>
<%= 1 / (Time.now - t) %>
<% end %>

your test is still flawed as the above poster mentioned… but this will
correct the behavior you were previously seeing…

ilan

how is my test flawed? I wasn’t looking to see if each iteration takes
different duration. I was really try to run a simple loop and see how
many hits the server can take per second. be careful when you say
people’s code is flawed, as it insults people. maybe you don’t know
about it.

Frederick C. wrote:

On 22 Apr 2009, at 21:39, SpringFlowers AutumnMoon wrote:

how is my test flawed?

Exactly as I explained previously: you are benchmarking how long it
takes to render an erb template, but there’s a lot of other bits of
overhead that will go into your overall requests/second.

Fred

and that’s why i said it is just a ball park figure (just for the
templating part). for example, if my webpages are dynamic and with very
little processing, then maybe it can serve 1800 pages per second? (i
got to try when i get home). also, maybe i can remove any code at all
and just put some static content there and see how long it takes to
serve that content.

On 22 Apr 2009, at 21:39, SpringFlowers AutumnMoon wrote:

how is my test flawed?

Exactly as I explained previously: you are benchmarking how long it
takes to render an erb template, but there’s a lot of other bits of
overhead that will go into your overall requests/second.

Fred

Why don’t you just use wget in a loop to time the entire rails
application? Something like this will hit your server with 1000
requests and tell you how long it took.

$ time for (( cnt = 0 ; cnt < 1000 ; cnt++ )) ; do /usr/bin/wget -nd -
q -O /dev/null http://localhost:3000/whateverpage ; done

Just remember to run in Production mode if you want any sort of
realism.

Brendon.

On Apr 22, 2:09 pm, SpringFlowers AutumnMoon <rails-mailing-

Well, the simpler way to do the above would be what Frederick
mentioned and use ab:

ab -n 1000 -c 20 http://local:3000/page/to/benchmark

You also get the bonus of getting a rough idea of how well your app
handles concurrent requests before choking.

I didn’t suggest ab or a bunch of other tools since he may not have
apache installed… but if he does, then that is better!

pharrington wrote:

Well, the simpler way to do the above would be what Frederick
mentioned and use ab:

ab -n 1000 -c 20 http://local:3000/page/to/benchmark

You also get the bonus of getting a rough idea of how well your app
handles concurrent requests before choking.

great. that works best. i thought fred had a typo when he typed
‘ab’…

i couldn’t use local here

used

ab -n 1000 -c 20 http://127.0.0.1:3000/hello/help

and it was great. thanks.

Brendon Whateley wrote:

I didn’t suggest ab or a bunch of other tools since he may not have
apache installed… but if he does, then that is better!

actually, isn’t ab just to test how the server performed? i used it and
it worked to test RoR on my macbook. thanks.

SpringFlowers AutumnMoon wrote:

Brendon Whateley wrote:

I didn’t suggest ab or a bunch of other tools since he may not have
apache installed… but if he does, then that is better!

actually, isn’t ab just to test how the server performed? i used it and
it worked to test RoR on my macbook. thanks.

(i mean it can be WEBrick or Mongrel and it doesn’t matter?)

Brendon Whateley wrote:

Sure it can test any web server. I just meant that since it is part
of the apache package not everybody would have it installed.

On Apr 23, 12:33�pm, SpringFlowers AutumnMoon <rails-mailing-

oh i see. thanks. fortunately the macbook with Leopard has it. i was
thinking of whether to set up a Linux machine to run Rails… but until
now there seems to be no reason to.

Sure it can test any web server. I just meant that since it is part
of the apache package not everybody would have it installed.

On Apr 23, 12:33 pm, SpringFlowers AutumnMoon <rails-mailing-