douxin0251
2017-04-07 11:41
浏览 131
已采纳

使用php-resque将数据排队到redis很慢

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"

图片转代码服务由CSDN问答提供 功能建议

我正在使用 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”
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongwei1895 2017-04-07 12:43
    最佳回答

    I found a way.

    Here are the steps:

    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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题