Optimizing Server Performance - Managing Load and Blocking Unwanted Access

Effective management of server load and security is crucial for maintaining the optimal performance of web applications. It ensures that resources are utilized efficiently and protects against potential security breaches. This guide will walk you through the process of identifying resource-intensive processes and securing your web applications by managing access.
Identifying Resource-Intensive Processes
Using `top` Command
- Access the Command Interface - Open your command line tool or terminal.
- Run the
top -cCommand - This command displays active processes. To execute, typetop -cand press Enter. - Sort by CPU Usage - Press
Shift+Pto sort processes by CPU usage, helping you quickly identify which applications are consuming the most resources. - Sort by Memory Usage - Press
Shift+Mto organize processes by memory usage, which is useful to see which processes are using the most RAM.
Cross-Referencing with Access Logs
- Locate Access Logs - For Nginx servers, access logs can typically be found at
-/home/user/logs/nginx/webappname_access.log.
- For OLS servers, look under/home/user/logs/.
- Remember to replaceuserandwebappnamewith actual values specific to your setup. - Check the Access Log - Open the log file to view the entries, which will help you correlate high resource usage with specific web requests.
Note: The setup of where your project is located could vary depending on your initial server setup.
Analysing Web Application Access
Tracking IP Hits and URL Access
Command for IP Hits
$ cat access.log | grep "add date here" | awk '{print }' | sort -n | uniq -c | sort -nReplace access.log with your actual log file name and add date here with the specific date you're investigating. This command lists the IP addresses and the number of times they've accessed your server.
Command for URL Access
$ cat access.log | grep "add date here" | awk '{print $7}' | sort -n | uniq -c | sort -nThis command helps you identify which URLs are being accessed the most on the specified date.
Addressing Unwanted Access
Blocking Suspicious IPs
- Add IP Address to your server Firewall Settings
On different hosting platforms you are able to add rules to block IPs or IP ranges. Consult your hosting environment on how to add rules. - Using Cloudflare
If you are using Cloudflare, you can add the specific IP or Ranges to your WAF rule set to block access to your server or application.
Managing Database Server Load
Monitoring Database Processes
To check active database processes, use the command
$ mysqladmin proc stat
This tool provides a snapshot of what's happening within your MariaDB or MySQL database, allowing you to pinpoint issues related to database load.
Conclusion
Regular monitoring and management of server load are key to ensuring that your web applications run smoothly and securely. By employing the steps outlined in this guide, you can efficiently identify and address performance bottlenecks and secure your servers against unauthorized access.
By implementing these practices, you'll not only enhance the performance of your servers but also improve the overall security and reliability of your web applications.
