【问题标题】:A Busy Php script making other scripts slower- how?一个繁忙的 PHP 脚本使其他脚本变慢 - 如何?
【发布时间】:2012-11-04 03:18:29
【问题描述】:

在我的本地服务器 XAMPP 环境中,我正在运行一个测试 PHP 脚本,它需要 20 秒才能运行,但只使用 2MB 内存和 10% 的 CPU。

当我打开一个新窗口并与第一个窗口同时运行相同的脚本时,两个脚本都需要 30 多秒才能完成。

--脚本是一个简单的for循环,写入mysql DB,InnoDb,200次。

脚本不应该花费相同的时间,但使用更多的系统资源吗?

如,线性缩放。

这是为什么?

  //the code in all its glory-- Post extends a CRUD class
  // These are the values to be saved:
   $values = array(
  'id' => '',
  'content' => 'This is the VALUE'
                 );
  //And the action. I know-Saving Mysql in a loop is a no-no-- 
    //for demonstration only  
   for($i=0; $i<250; $i++){

   $object = new Post($values); //instantiate the Post Class with values
   $object->create($values);   //save the values to the Db. The end
                           }

20 秒。

【问题讨论】:

  • innodb 执行行级锁定。两个脚本是否都试图更新相同的行?两个脚本都在开始交易吗?
  • 200 行 20 秒?那里出了点问题
  • 不,只是一个简单的插入,两列。
  • @Dagon 是的,这太慢了......不过,它应该线性增加时间,不是吗?
  • @Dagon 同意——我对 POG-phpobjectgenerator.com 做了同样的测试——在同一时间段内保存了大约 800 行。

标签: php performance concurrency


【解决方案1】:

似乎它正在创建一个数据库上的锁。所以 1 不能在另一个之前完成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    相关资源
    最近更新 更多