Slow console performance usually gives the impression that the server is under heavy load and therefore commands execute with a long delay, but this is not always the case.
There are other reasons for slow console response when running basic commands such as top, ping, iostat.
To determine the exact cause of the delay, we will use the strace command.
1. Installation
apt install strace
2. Example usage
2.1 Show everything
strace -r top -n 1
2.2 Summarize the total
strace -r top -c 1
Since the output contains too much information, a more compact variant can be used:
strace -r -e trace=connect,poll,openat,stat -o top_small.log top -n 1
3. Analyzing the output
0.000231 poll([{fd=3, events=POLLIN}], 1, 5000) = 0 (Timeout)
5.003045 poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
The system call poll with a timeout of 5000 ms did not receive a response from the DNS server (8.8.8.8). This took exactly 5 seconds.
5.005113 poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
Immediately after the first one, top tries to make the request again, using the same DNS server, and again waits 5 seconds.
4. Conclusion
The delay in executing the command of 10 seconds is not related to server load, but to the long wait for a response from the DNS server specified in /etc/resolv.conf.
If you are using the global DNS from Google, it may simply be blocked in certain countries, as was the case in our situation. Just change it to one located in your country.

