Forum: Ruby on Rails why does number of hits per second go from 1800 to 20?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-22 18:35
i had the following code to ball-park the number of possible hits per
second my macbook can support:

<% t = Time.now %>
<h1>Hello#index</h1>
<p>Find me in app/views/hello/index.rhtml</p>

<pre>
<% 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-22 19:40
(Received via mailing list)
On Apr 22, 5:35 pm, SpringFlowers AutumnMoon <rails-mailing-
l...@andreas-s.net> 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
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-22 19:49
Frederick Cheung 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-22 19:54
(Received via mailing list)
On Apr 22, 6:49 pm, SpringFlowers AutumnMoon <rails-mailing-
l...@andreas-s.net> 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
391f9b787cdc12aa2c179713f5103e3a?d=identicon&s=25 Ilan Berci (iberci)
on 2009-04-22 21:31
Change this:
> <% t = Time.now %>
> <h1>Hello#index</h1>
> <p>Find me in app/views/hello/index.rhtml</p>
>
> <pre>
> <% 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
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-22 22:39
Ilan Berci wrote:
> Change this:
>> <% t = Time.now %>
>> <h1>Hello#index</h1>
>> <p>Find me in app/views/hello/index.rhtml</p>
>>
>> <pre>
>> <% 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-22 22:50
(Received via mailing list)
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
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-22 23:09
Frederick Cheung 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.
054ea2f04b5592b91f8223796cc53979?d=identicon&s=25 Brendon Whateley (brendon)
on 2009-04-23 03:20
(Received via mailing list)
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-
885ac43bca92fc2b1034356f3283e788?d=identicon&s=25 pharrington (Guest)
on 2009-04-23 04:20
(Received via mailing list)
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.
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-23 16:21
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.
054ea2f04b5592b91f8223796cc53979?d=identicon&s=25 Brendon Whateley (brendon)
on 2009-04-23 21:13
(Received via mailing list)
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!
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-23 21:32
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.
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-23 21:33
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?)
054ea2f04b5592b91f8223796cc53979?d=identicon&s=25 Brendon Whateley (brendon)
on 2009-04-24 00:15
(Received via mailing list)
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-
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-04-24 00:27
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.
This topic is locked and can not be replied to.