Optimizing Server Performance - Managing Load and Blocking Unwanted Access

3 min read

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

  1. Access the Command Interface - Open your command line tool or terminal. 
  2. Run the top -c Command - This command displays active processes. To execute, type top -c and press Enter.
  3. Sort by CPU Usage - Press Shift+P to sort processes by CPU usage, helping you quickly identify which applications are consuming the most resources.
  4. Sort by Memory Usage - Press Shift+M to organize processes by memory usage, which is useful to see which processes are using the most RAM.

Cross-Referencing with Access Logs

  1. 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 replace user and webappname with actual values specific to your setup.
  2. 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 -n

Replace 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 -n

This command helps you identify which URLs are being accessed the most on the specified date.

Addressing Unwanted Access

Blocking Suspicious IPs 

  1. 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.
  2. 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.