Hi,
first of all, sorry for my english.
to start, here my config :
Server linux : ubuntu 8.4
Rails : 2.3.4
Ruby : 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
I wanted to test the charge capacity of my server, and I saw a problem
with the multithrearding on Ror.
Here the config file on the server
config/environments/development.rb
Code :
config.threadsafe!
Here the ruby file on the server
app/controllers/hello_controller.rb
class HelloController < ApplicationController
def word
$startTime = Time.now
for valeur in 1..10000000
end
$stopTime = (Time.now - $startTime)
render :text => "Hello Word!!!!, id: "+params["id"]+",
temps: "+$stopTime.to_s
end
end
And the script of “loading test” :
helloWord.sh
#!/bin/bash
count=0
while [ $count -lt $1 ]
do
php helloWord.php $count &
count=expr $count + 1
done
And the client script
$url = “http://”.URL_AMV.“/hello/word?id=”.$id;
$timeStart = microtime(TRUE);
echo “end of “.$id.” to “.$timeStart.”\n”;
$retour = file($url);
$timeStop = microtime(TRUE);
echo “end of “.$id.” to “.$timeStop.”\n”;
echo “Total for “.$id.” => “.$totalTime.”\n”;
echo $url.“\n”;
print_r($retour);
The result is :
./helloWord.sh 5
start of 0 to 1285767141.33
start of 1 to 1285767141.332
start of 2 to 1285767141.37
start of 3 to 1285767141.3795
start of 4 to 1285767141.406
end of 0 to 1285767142.2877
Total for 0 => 0.958
http://87.98.167.204:4445/hello/word?id=0
Array
(
[0] => Hello Word!!!, id: 0, temps: 0.760337
)
end of 1 to 1285767143.1712
Total for 1 => 1.839
http://87.98.167.204:4445/hello/word?id=1
Array
(
[0] => Hello Word!!!, id: 1, temps: 0.760326
)
end of 2 to 1285767143.9855
Total for 2 => 2.616
http://87.98.167.204:4445/hello/word?id=2
Array
(
[0] => Hello Word!!!, id: 2, temps: 0.760426
)
end of 3 to 1285767144.8673
Total for 3 => 3.488
http://87.98.167.204:4445/hello/word?id=3
Array
(
[0] => Hello Word!!!, id: 3, temps: 0.760231
)
end of 4 to 1285767145.6874
Total for 4 => 4.281
http://87.98.167.204:4445/hello/word?id=4
Array
(
[0] => Hello Word!!!, id: 4, temps: 0.764974
)
and the log is :
Processing HelloController#word (for 80.13.147.95 at 2010-09-29
15:31:53) [GET]
Parameters: {“id”=>“0”}
Completed in 763ms (View: 0, DB: 1) | 200 OK [http://87.98.167.204/
hello/word?id=0]
SQL (0.2ms) SET client_min_messages TO ‘panic’
SQL (0.1ms) SET client_min_messages TO ‘notice’
Processing HelloController#word (for 80.13.147.95 at 2010-09-29
15:31:54) [GET]
Parameters: {“id”=>“1”}
Completed in 763ms (View: 0, DB: 1) | 200 OK [http://87.98.167.204/
hello/word?id=1]
SQL (0.2ms) SET client_min_messages TO ‘panic’
SQL (0.1ms) SET client_min_messages TO ‘notice’
Processing HelloController#word (for 80.13.147.95 at 2010-09-29
15:31:55) [GET]
Parameters: {“id”=>“2”}
Completed in 763ms (View: 0, DB: 1) | 200 OK [http://87.98.167.204/
hello/word?id=2]
SQL (0.2ms) SET client_min_messages TO ‘panic’
SQL (0.1ms) SET client_min_messages TO ‘notice’
Processing HelloController#word (for 80.13.147.95 at 2010-09-29
15:31:56) [GET]
Parameters: {“id”=>“3”}
Completed in 763ms (View: 0, DB: 1) | 200 OK [http://87.98.167.204/
hello/word?id=3]
SQL (0.2ms) SET client_min_messages TO ‘panic’
SQL (0.1ms) SET client_min_messages TO ‘notice’
Processing HelloController#word (for 80.13.147.95 at 2010-09-29
15:31:57) [GET]
Parameters: {“id”=>“4”}
Completed in 767ms (View: 0, DB: 1) | 200 OK [http://87.98.167.204/
hello/word?id=4]
what are we seeing?
- 5 process run together
- Ruby take the same time for each process (760 ms)
- BUT : RoR wait the end of each process before answer to client.
finally :
I think, there is a probleme somewhere. but WHERE?? could you help me
please?
regards,
Yann (geek)