Can I put a caching server in front of my website?

I have a website using apache httpd as server and mysql as backend. He publishes a “Thought of the Day,” which is so popular that the server crashes due to the number of requests. Since the same page is being requested (the thought changes only once a day), is it possible to put a caching server in front of my main server, so when the same request is processed by different clients, the caching server returns the page without having to access the database ?

+4
source share
8 answers

For slow removable pages, cache will certainly reduce CPU usage; but in your last resort, when the page changes once a day, and this is predictable, it would be much easier to use a simple and fast static file server ( lighthttp , nginx , etc.) and the cron task to change the "thought" every night of the day. "

In fact, many non-interactive web pages can be made this way: periodically rebuild html files from a database or any other source and use simple, fast static web servers.

+12
source

That's right. There are many products that will work well for this. Apache itself can be configured in this way, although if you are running Linux or UNIX, Squid is the best option because it is specifically designed to do the job.

On Windows, MS has always offered cache / proxy products that will perform this function. This is currently ISA Server 2006. Although this type of application is heavily overloaded.

Squid is my recommendation.

+2
source

Yes. You are talking about reverse proxy (or "HTTP accelerator", which is an inaccurate term for the same thing). This can be very effective, and so many high-performance sites use this technique.

A key element to make the right choice is the HTTP headers related to caching. Therefore, I highly recommend reading the HTTP RFC (this really can be done). If you do not get the right headings, you may have little effect or even security problems (if personalized pages are cached and presented to the wrong people).

Also: you may need to split your page into parts to get the best caching effect. Example. If you insist that the clock in the corner of your pages display the current server time until the second, then the whole page becomes cached for only a second. So, 1) drop the stupid clock, or 2) whether they create the client side of the script - or 3) so that the client side of the script pulls out this particular part of the page from a special URL, which then displays only a small constantly changing, non-cached piece of HTML.

I once used Squid as a reverse proxy for a large website. Currently, if I do this again, I will try Varnish .

+2
source

I would definitely recommend the Javier solution, which is the simplest, most reliable and easiest to maintain. Just remember to send the correct Expires header within 24 hours to the future and install ETags correctly.

+2
source

If your “thought for a day” page never changes except once a day, maybe the simple task is to run something like this once a day

wget http: //your_site/your_page.php -O / var / www / your_site_directory / your_page.html

(and change the links to this page from your_php .php to your_page.html)

Then you reduce the load on your Apache server and your SQL server ...

+1
source

You can also try memcached . This is what my company uses, and I think LiveJournal uses it too. It caches database queries and makes a serious mistake in accessing the database.

0
source

I can no longer accept Javier’s proposal (create a static web page). I just want to add one point to clarify it a bit:

Save the static file as ".html" and not ".php" or any other language used to output data from the database. Using static files is much faster than running a parser or executable. Static files (HTML, GIF, ...) are simply transferred to the network, while scripts, CGI and all other things are launched, analyzed, executed and something else ... This will require much more server resources than real .

0
source

A static file simply has input / output as auxiliary. The objects cached in memory are great, but you still have the overhead of managing these objects, and with heavy use, it gets complicated. Hence the ease and beauty of static files.

Another advantage is that you can have processes that are NOT part of the web server threads that perform updates and maintenance. If you update service locks, you will not block your web server.

0
source

Source: https://habr.com/ru/post/1277475/


All Articles