# Linux OS Performance

> Still working on building this page..

Here's a list of commands that I find useful when debugging issues around the performance of Linux VMs when an application is running slow. Through these commands, I try to get a good idea of what might causing the slow performance of the OS and the application.&#x20;

**Check the server load**&#x20;

```bash
uptime 
#Check load averages to see if anything seems odd.

```

**Check the RAM and CPU usage at a glance with processes**

```bash
htop
#Check if the CPU and the RAM usages are maxing out.
```

**List processes that might seem**

```bash
ps aux | grep <PID/Process Name>
```

**Check the RAM utilization**

```bash
vmstat -Sm 1
#Check r, free, buff, cache, us, sy
```

**Check the disk performance**

```bash
iostat -xmdz 1
#Workload (r/s, w/s, rMB/s, wMB/s), Resulting Performance( avgqu-sz, await, svctm, %util),
```

**Check the processor performance**

```bash
mpstat -P ALL 1
#Look for hot CPUs by checking the %idle time.
```

**Check the amount of free and cached memory**

```bash
free -m
#Check block device I/O cache (Buffers) and virtual page cache (Cached)
```

**Check the network I/O**

```bash
 sar -n DEV 1 #Report Network device statistics
 sar -n TCP,ETCP,DEV 1 #Report the incoming and outgoing tcp connections along with network device stats.
```

**Check the network performance**

```bash
netstat -s
netstat -tnlp
netstat -r #prints the route table
#Get to know the things happening at the tcp level.
#Check with applications are using which ports
```

**Check the network interface performance**

```bash
nicstat 1
#Get the network interface statistics
#check the network throughput (read, writes) and interface %util
```

**Check the process stats**

```bash
pidstat -t 1 #%user, %system
pidstat -d 1 #Disk I/O
#Very useful process stats, e.g. by thread or disk I/O
```

**Trace System Calls**

```bash
strace -p <pid>
strace -tp ‘pgrep <process>’ 2>&1 | head -100
#system call tracer - basically records all the system calls going on.
```

**Trace Network Packets**

```bash
tcpdump 
```

**Trace Kernel Message**

```bash
dmesg | tail
#Check if there are any errors
```

References: I have compiled this list through Brendan Greggs's talk and slide deck. He is a legend in this space. Find him [here](https://www.brendangregg.com/).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cp.rohanthe.dev/linux-essentials/linux-os-performance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
