简体   繁体   English

mysql + php加速

[英]mysql + php speed up

php script 1 -INSERT 500 record per second and php script 2 -UPDATE some data to that table (500 per second) php脚本1-每秒插入500条记录,php脚本2-将某些数据更新到该表(每秒500条)

Web application SELECT data to the database to view data, draw statistic, etc Web应用程序将数据SELECT到数据库中以查看数据,绘制统计信息等

My problem is, it take long loading time to view data while the application inserting/updating data to table same time. 我的问题是,在应用程序同时将数据插入/更新到表的过程中,查看数据需要很长时间。

can anyone provide a solution for this? 谁能为此提供解决方案?

Thanks in advance 提前致谢

You can use just one query for inserting: 您只能使用一个查询来插入:

Example: 例:

INSERT INTO table (id,value) VALUES (1,2), 
                                    (2,3), 
                                    (3,4),
                                     ...

On some condition that applies to UPDATEs too 在某些情况下也适用于UPDATE

Edit 编辑

Based on your comment you can use INSERT DELAYED 根据您的评论,您可以使用INSERT DELAYED

Or you can use apccache or memcached to initially store the values in the memory than flush it into db each X time with the query above 或者,您可以使用apccache或memcached最初将值存储在内存中,而不是使用上述查询每X次将其刷新到db中

If your SELECT clauses are mostly aggregate data or it's not mission critical that they be absolutely accurate every time they are called, you could try changing the isolation level to READ COMMITTED , or READ UNCOMMITTED which should give you a speed increase on the SELECT clause. 如果您的SELECT子句主要是聚合数据,或者在每次调用它们时绝对不是绝对关键,那么您可以尝试将隔离级别更改为READ COMMITTEDREAD UNCOMMITTED ,这将使您在SELECT子句上的速度有所提高。 You can read about the differences here: 您可以在此处了解不同之处:

http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM