0

I have an app that is posting data from android to some MySQL tables through PHP with a 10 second interval. The same PHP file does a lot of queries on some other tables in the same database and the result is downloaded and processed in the app (with DownloadWebPageTask).

I usually have between 20 and 30 clients connected this way. Most of the data each client query for is the same as for all the other clients. If 30 clients run the same query every 10th second, 180 queries will be run. In fact every client run several queries, some of them are run in a loop (looping through results of another query).

My question is: if I somehow produce a textfile containing the same data, and updating this textfile every x seconds, and let all the clients read this file instead of running the queries themself - is it a better approach? will it reduce serverload?

4

2 回答 2

1

在我看来,您应该考虑使用 memcache。

它将让您将数据存储在内存中,这甚至比磁盘上的文件或 mysql 查询更快。

它还可以减少数据库的负载,这样您就可以使用相同的服务器/数据库设置为更多用户提供服务。

Memcache 非常易于使用,互联网上有很多教程。

这是一个可以帮助您入门的方法:

http://net.tutsplus.com/tutorials/php/faster-php-mysql-websites-in-minutes/

于 2013-09-08T12:07:38.673 回答
0

您需要的是缓存。您可以缓存来自数据库的数据或缓存页面本身。您可以在下面找到一些关于如何在 PHP 中执行相同操作的链接:

http://www.theukwebdesigncompany.com/articles/php-caching.php http://www.addedbytes.com/articles/for-beginners/output-caching-for-beginners/

是的。这将大大减少数据库服务器的负载。

于 2013-09-08T11:42:52.443 回答