Solve performance problems.
Initial data.We broadcast football matches via the Internet. Visitors: 5,000-10,000 on regular days, 100,000-150,000 on match days.
In the data center- 5 web servers with apache and PCP, hung out through hardware load balancer
- 2 memkesh pools: for sessions and data from web services
ProblemWith a large influx of visitors, the local network is overloaded due to the large number of calls to the memksh.
Aggravating factors : 100 Mbit network, both pools on the same servers.
Solutions- Increasing the network to 1Gbit after the end of the series of matches
- Increase cache storage time (as a temporary measure)
- Using smart session technology
Today we will talk about the technology of smart sessions, which we used to reduce the load.
')
What is the essence of technology
- We do not create a session if it is not really needed.
- We do not update the session in the repository, if it has not changed.
In fact, our site is paid, even if we have 150,000 unique per day, then there are really few people willing to pay. Visitors are distributed approximately as follows:
- 70% - Gawker. They opened the main page, they realized that it wasn’t what they needed, they closed it. That is, S worked well, and rake us.
- 28% - Fans. There is no money, but use our site to keep track of information during the match (goals, substitutions). Usually not recorded, because the information is available and so.
- 2% - Really watching the matches, registering and paying.
Implementation
Since we use memkesh, we already have a Session object, which overloads the standard session functionality and allows us to store the latest in memkesh. Additionally we do the following:
- We put the global session_start () in if so that the session is not created when not asked.
if(!empty($_COOKIE[ini_get('session.name')]))
session_start();
- In the place where the user log in we add the start of the session, because here it is already necessary:
if(empty($_COOKIE[ini_get('session.name')]))
session_start();
- And finally, in our object we create an additional static variable, where we store the contents of the session while reading, and during writing we do the following check at the very beginning:
if(self::$data !== null && self::$data == $currentData)
return strlen($currentData);
Voila, partially the load on the network is reduced, on memkes too. Then they switched the caching of parts of the blocks to local web servers and were able to wait for the visitors to decline painlessly, after which they increased the network bandwidth.
Comments are welcome.
UPD : The essence of the post is not to show me how cool I am, but the fact that there are trivialities in PCPs that are so mundane that we stop paying attention to them, and in fact sometimes they are not too thought out and have an impact on performance.