php - 性能问题 : Load data infile is making select query slow

标签 php mysql performance yii

我有一个每天 24 小时扫描 twitter、facebook、google+ 的程序。每个用户运行一个搜索列表并插入(一次 100 个结果,函数循环运行直到没有更多结果)

Yii::app()->db->createCommand(
     "LOAD DATA INFILE '/var/tmp/inboxli_user".$user.".txt'
      INTO TABLE inbox
      FIELDS TERMINATED BY ',$%'
      LINES STARTING BY 'thisisthebeginningxxx'
          (created_on, created_at, tweet, tweet_id, profile_image,
           twitter_user_id, screenname, followers, lang, tags, type,
           positive_score, readme, answered, deleted, searchlist_id,
           handled_by, used_as_newsitem,  user_id)
     "                       )->execute();

进入数据库以保持服务器上的负载尽可能小。但是,当我的函数执行批量插入时,我的选择函数运行速度非常慢。通常收件箱会在 1.5 秒内加载,但当插入运行时,有时打开一个页面需要大约 20 秒。

我的问题是如何优化它?那么插入和选择可以同时使用数据库而不会减慢速度吗?

最佳答案

  • 离开 MyISAM!使用 InnoDB;它在不锁定其他操作方面做得更好。
  • 加载数据非常高效,将计数增加到 500。
  • 你有什么索引?让我们看看 SHOW CREATE TABLEDROP 任何不必要的索引;这将加快 LOAD
  • 考虑关闭查询缓存。

关于php - 性能问题 : Load data infile is making select query slow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36465398/

相关文章:

javascript - 从ajax请求调用的php文件中获取变量

php 64 位 php_int_max = 2147483647

mysql - mysql查询需要注意什么,比如%?

php - 在foreach循环中插入多个表单数据

php - 如何在一定时间后采取行动(因用户而异)?

javaws.exe 与 java8 中的 java.exe 相比性能较差

android - Gingerbread 模拟器实例比 Froyo 及以下版本更慢。为什么?

c - 您使用什么工具来衡量绩效?

php - 内容更改时从头开始重新创建 index.html

php - 调用未定义的方法 Illuminate\Database\Query\Builder::table()