我正在bulk inserts
使用RealTime Index
PHP 和禁用 AUTOCOMIT ,例如
// sphinx connection
$sphinxql = mysqli_connect($sphinxql_host.':'.$sphinxql_port,'','');
//do some other time consuming work
//sphinx start transaction
mysqli_begin_transaction($sphinxql);
//do 50k updates or inserts
// Commit transaction
mysqli_commit($sphinxql);
并让脚本在一夜之间运行,早上我看到
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate
212334 bytes) in
所以当我仔细检查nohup.out
文件时,我注意到这些行
PHP Warning: mysqli_query(): MySQL server has gone away in /home/script.php on line 502
Warning: mysqli_query(): MySQL server has gone away in /home/script.php on line 502
这些行之前的内存使用量是正常的,但是这些行之后的内存使用量开始增加,并且它击中php
mem_limit
并给了PHPFatal error
并死了。
in script.php , line 502 is
mysqli_query($sphinxql,$update_query_sphinx);
所以我的猜测是,狮身人面像服务器在几个小时/分钟不活动后关闭/死亡。
我试过在 sphinx.conf 中设置
client_timeout = 3600
重新开始搜索
systemctl restart searchd
我仍然面临同样的问题。
那么,当长时间没有活动时,我怎么能不让 sphinx 服务器死在我身上呢?
添加了更多信息 -
我一次从 mysql 获取 50k 块的数据,并执行 while 循环来获取每一行并在 sphinx RT 索引中更新它。像这样
//6mil rows update in mysql, so it takes around 18-20 minutes to complete this then comes this following part.
$subset_count = 50000 ;
$total_count_query = "SELECT COUNT(*) as total_count FROM content WHERE enabled = '1'" ;
$total_count = mysqli_query ($conn,$total_count_query);
$total_count = mysqli_fetch_assoc($total_count);
$total_count = $total_count['total_count'];
$current_count = 0;
while ($current_count <= $total_count){
$get_mysql_data_query = "SELECT record_num, views , comments, votes FROM content WHERE enabled = 1 ORDER BY record_num ASC LIMIT $current_count , $subset_count ";
//sphinx start transaction
mysqli_begin_transaction($sphinxql);
if ($result = mysqli_query($conn, $get_mysql_data_query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
//sphinx escape whole array
$escaped_sphinx = mysqli_real_escape_array($sphinxql,$row);
//update data in sphinx index
$update_query_sphinx = "UPDATE $sphinx_index
SET
views = ".$escaped_sphinx['views']." ,
comments = ".$escaped_sphinx['comments']." ,
votes = ".$escaped_sphinx['votes']."
WHERE
id = ".$escaped_sphinx['record_num']." ";
mysqli_query ($sphinxql,$update_query_sphinx);
}
/* free result set */
mysqli_free_result($result);
}
// Commit transaction
mysqli_commit($sphinxql);
$current_count = $current_count + $subset_count ;
}