php mysql进程表,快速填充

时间:2015-05-13 11:51:03

标签: php mysql gearman

我有一个问题:

我有一张这样的桌子(只是一个例子)

table:
id int auto_increment
user_id int,
ts timestamp,
type int,

和其他一些数据,每秒插入大量数据。

我有一个gearman任务来处理这些数据。(下面的代码示例)

<?php
     while(true) {
         // this method removs all data older than 1 day
         clear_old_data() 
         //fetches data with ts(timestamp) not older than 15 minutes
         //here is sql
         //type = 2 = data which i need to select
         $SQL = 'SELECT * FROM my_table where type = 2 and ts < unix_timestamp() - 15';
         $data = get_data_from_table($SQL);
         //than i am doing fetch each row and processing data
         while ($row = $data->fetchRow(PDO::FETCH_ASSOC)) {
             //do some stuff here
            // and set type to 4(processed)
         }

     }
     ....
?>

代码很快,我每次迭代(9000行)测试id为microtime 2分钟左右。

我的问题是:每秒插入大量数据,这个速度不足以快速处理行。 我需要找到一个解决方案,以并行模式运行此代码或此代码的2-3-4-5 -...实例。 但我不知道在哪里看,做什么,我被卡住了。

也许我需要更改我的sql(以并行模式运行它)。

SELECT * FROM my_table where type = 2 and ts < unix_timestamp() - 15

我很感激任何建议

0 个答案:

没有答案
相关问题