我正在从Magento数据库中获取6k篇文章。在开始时遍历它们非常快(0秒,只有几毫秒)并且变得越来越慢。循环大约需要8个小时才能运行,最后,foreach中的每个循环大约需要16-20秒!看起来mysql最终越来越慢,但我无法解释原因。
$product = Mage::getModel('catalog/product');
$data = $product->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('type_id', 'simple');
$num_products = $product->getCollection()->count();
echo 'exporting '.$num_products."\n";
print "starting export\n";
$start_time = time();
foreach ($data as $tProduct) {
// doing some stuff, no sql !
}
有谁知道为什么这么慢?它会更快,只需要获取ID并逐个选择每个产品吗?
运行此代码的脚本的内存使用量具有恒定的内存使用率:
VIRT RES SHR S CPU% MEM%
680M 504M 8832 R 90.0 6.3
此致,Alex
答案 0 :(得分:2)
已经注意到死亡阵列(tm),这是新版本中的官方修复。也许数据会再次出现!
摘自已修补内存泄漏的1.4.2.0rc1 /lib/Varien/Db/Select.php
public function __construct(Zend_Db_Adapter_Abstract $adapter)
{
parent::__construct($adapter);
if (!in_array(self::STRAIGHT_JOIN_ON, self::$_joinTypes)) {
self::$_joinTypes[] = self::STRAIGHT_JOIN_ON;
self::$_partsInit = array(self::STRAIGHT_JOIN => false) + self::$_partsInit;
}
}
摘录自1.4.1.1 /lib/Varien/Db/Select.php内存泄漏
public function __construct(Zend_Db_Adapter_Abstract $adapter)
{
parent::__construct($adapter);
self::$_joinTypes[] = self::STRAIGHT_JOIN_ON;
self::$_partsInit = array(self::STRAIGHT_JOIN => false) + self::$_partsInit;
}