How we r.uc. server load by removing 570!000 unnecessary sessions per day
In one of the projects! we encounter. a problem: up to 600!000 session files were creat. daily. It would seem that the solution is obvious – r.uce the session storage time to one day! but the customer requir. storage for six months.
Next! we conduct. a detail.
Study of the Nginx logs and the session files themselves to find out where the load was coming from. It turn. out europe cell phone number list that most of the sessions were creat. by bots ~570!000 requests per day. Despite the number of requests! the server spent resources on finding and processing the corresponding sessions! which negatively affect. performance.
We us. Memcach. – it didn’t work because of its high RAM consumption.
Storing sessions in a database install woo commerce to create your online store would increase the load on the server several times.
During the analysis of server logs! it was discover. that sessions creat. by bots load the system and take up resources. To solve this problem! a Bash script was develop. that automatically analyzes and deletes session files creat. by bots.
How does the script work?
Extracts IP addresses from session files.
Checks IP in access.log for search engine optimization mails signs of User-Agent bots.
Finds bots using regular expressions.
Deletes session files if the owners are bots.
As a result! the site’s performance has increas.. Now pages load faster! and the server processes incoming requests without unnecessary load! ensuring stable and fast operation of the platform.
Conclusion
Dealing with overloads is a balance between hardware! code! and infrastructure. Buying a powerful server without optimizing the code will still cause the site to slow down. Adding dozens of servers when the database can’t handle the load will still cause problems.
To avoid overloads! it is important to monitor RPS! use horizontal scaling! load balancing! caching and optimize the code. We regularly apply these methods in practice and see that with the right settings! the system can withstand even the most severe loads.