私はPHP を使用して、 AUTOCOMIT を無効にすることで行っていbulk inserts
ました。RealTime Index
// 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
PHP を与えFatal error
て死亡しました。
in script.php , line 502 is
mysqli_query($sphinxql,$update_query_sphinx);
私の推測では、スフィンクス サーバーは、数時間/分の非アクティブ状態の後に閉じられた/停止しました。
私はsphinx.confで設定しようとしました
client_timeout = 3600
検索を再開しました
systemctl restart searchd
それでも私は同じ問題に直面しています。
では、アクティビティが長時間存在しない場合、どうすればスフィンクスサーバーを停止させることができますか?
詳細情報が追加されました -
一度に 50k チャンクで mysql からデータを取得し、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 ;
}