I'm using php-resque for queuing my jobs. And I'm doing apache ab tool to benchmark my performance.
php-resque
does good job, but it's slow as every time my it connects to redis which impacts performance (without connection it handles ~130 Requests/sec
and with Resque::enqueue
it's ~30 requests/sec
).
So I was thinking to pass data to another file through exec
which will connect redis and queus job in the background, but found that exec
is way much slow.
What is next ? How can I make it handle redis queuing faster.
Note: I'm using this command to test performance.
ab -n 1000 -c 10 "http://localhost/index.php"
I found a way.
After digging php-resque
I found that it's using fsockopen which makes it slow.
Then I installed php-redis
on my ubuntu machine. By executing following command.
sudo apt-get install php5-redis
Then restarted apache server by :
sudo service apache2 restart
And then connected with redis by following lines of code.
<?php
$redis = new Redis();
$result = $redis->connect('127.0.0.1');
$id = md5(uniqid('', true));
$redis->set("resque:job:$id",$args);
$redis->close();
unset($redis);
After this code testing with gave better performance (~70 requests/second)
which is doubled than before.
Note: here pconnect
stands for persistent connection, which is faster than connect
.
Hope this helps someone.