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

使用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"
  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸