weixin_33698043 2016-04-24 18:21 采纳率: 0%
浏览 433

插入MYSQl太慢

User keys in search parameters, then we make a request to a data provider and redirect user to a loading page. The response from the data provider hits a callback url, in which case we parse the results and store about 200 rows into the db. Meanwhile the loading page uses ajax to query the db every second and when the results are all there we display the results to the user.

The issue is that insert into the mysql db is too slow. We know the response back from the data provider comes back within seconds, but the processing of the script and inserting of rows into the db is very slow. We do use multirow insert.

Any suggestions to improve? FYI, the code is hugely long... that's why not displaying right now.

  • 写回答

2条回答 默认 最新

  • weixin_33696822 2016-04-24 18:31
    关注

    There are multitude of factors affecting your insertions:

    1) slow hardware and bad server speeds. Sol : Contact your server administrator

    2) Use something other than InnoDB

    3) Use a surrogate key , other than your primary key that is numeric and sequential along with your natural primary key.

    OR

    4) Try this https://stackoverflow.com/a/2223062/3391466.

    评论
  • helloxielan 2016-04-24 18:31
    关注

    Suggestion: Instead of running the code on one page and having the user wait the whole process, why not have the php page store the instructions in a php queue? The instructions would then be executed by a separate php script (for instance a Cron Job) and the user wouldn't have to wait for the whole process to take place.

    However, in this situation it would be ideal to let the user know that the changes made can take a bit of time to update.

    Cron jobs are very easy to implement. In CPanel there is an option for Cron Jobs where you specify which script you want to run and in which intervals. You can let your script know to run once every 1 minute (or more or less depending on how much demand there is). From there your script would check the queue and could keep on running until the queue is empty again.

    Let me know if that helped!

    评论

报告相同问题?

悬赏问题

  • ¥20 如何用Numpy库的向量化方法提高delta对冲的计算效率?(代码已附,只需修改第三个函数,在一小时内绘制出散点图即可)
  • ¥15 yolov5双目识别输出坐标代码报错
  • ¥15 这个代码有什么语法错误
  • ¥15 给予STM32按键中断与串口通信
  • ¥15 使用QT实现can通信
  • ¥15 关于sp验证的一些东西,求告知如何解决,
  • ¥35 关于#javascript#的问题:但是我写的只能接码数字和字符,帮我写一个解码JS问题
  • ¥15 prophet运行报错,如何解决?
  • ¥15 用GPU跑pytorch搭建的LSTM的时候出现了奇怪的报错
  • ¥20 前端数据是从session等作用域拿到的,如何取值继续传递后端呢