![](/img/trans.png)
[英]Optimising concurrent ImageMagick Requests using redis/php-resque
[英]Queuing data to redis with php-resque is slow
我正在使用php-resque排隊我的工作。 而且我正在使用apache ab工具來衡量我的表現。
php-resque
做得很好,但它很慢,因為每次我連接到redis都會影響性能(沒有連接它會處理~130 Requests/sec
和Resque::enqueue
它是~30 requests/sec
)。
所以我想通過exec
將數據傳遞給另一個文件,它將在后台連接redis和queus作業,但發現exec
的速度很慢。
下一步是什么 ? 如何讓它更快地處理redis排隊。
注意:我正在使用此命令來測試性能。
ab -n 1000 -c 10 "http://localhost/index.php"
我找到了一個方法。
在挖掘了php-resque
我發現它正在使用fsockopen ,這使得它很慢。
然后我在我的ubuntu機器上安裝了php-redis
。 執行以下命令。
sudo apt-get install php5-redis
然后通過以下方式重啟apache服務器:
sudo service apache2 restart
然后通過以下代碼行與redis連接。
<?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);
在此代碼測試之后提供了更好的性能(~70 requests/second)
,這比以前翻了一番。
注意:這里pconnect
代表持久連接,這比connect
更快。
希望這有助於某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.