开发者

MySQL query to reduce server load

开发者 https://www.devze.com 2023-02-17 11:27 出处:网络
I have a MySQL server running that will be queried regularly through a php front end. I\'m slightly worried about server load as there will be a fair amount of people accessing the webpage, with each

I have a MySQL server running that will be queried regularly through a php front end. I'm slightly worried about server load as there will be a fair amount of people accessing the webpage, with each session querying the database regularly. The results of the query, and in essence the webpage will be the same for all users.

Is there a way of querying the database once, and outputting the data/results to the webpage, from which开发者_运维知识库 all users connect to and view? Basically running the query for all users that connect to the webpage, rather than each user querying the database.

Any suggestions appreciated.

Thanks


You don't have to worry.
Databases intended for that.

Most sites in the world run exactly the same way: MySQL server running that will be queried regularly through a php front end. Nothing bad with it.

Well tuned SQL server and properly designed query will serve much more than you think. You will need exceptionally high traffic to start worrying about such things.
Don't forget that MysQL has it's own query cache.

Also please note that there are no users "connected" to the webpage. They connect, get page contents and disconnect.


You should give the server a try. If the server is overloaded, you can always try Memcached tool. It can be used via PHP or by MySQL directly. It will save you from querying DB server with similar queries, i.e. the load on server will be decreased drastically.


If the webpage will be the same for all users, why do you even need to have a MySQL backend?

I think the best solution would be to have a standalone script running periodically (e.g. as a cron) which generates the static HTML for your web pages. That way, there is no need for users to query the database when they are just going to end up with the exact same page anyway.


If its a large query with joins you could create a view in mysql with the queried data and query the view, and update the view if the data changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号