New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Help, my computer is sluggish
1. Help! My Computer is Sluggish
Kevin B. O'Brien
Washtenaw Linux Users Group
2. Just buy a new CPU!
This is what most people will try
It is actually a less likely way to solve your
problem
You need to diagnose the actual cause before
you know what to do
3. Some Suggestions
This presentation is not exhaustive
Linux has many, many tools for analyzing
computer problems
So we will cover just a few of the things you can
try
Read the man pages for the tools we cover.
There is a lot of added information there that
can help you do even more with the tools.
4. Hardware vs. Software
Hardware = the part of a computer you can hit
Software = the part you can't hit
A computer is always a combination of both
hardware and software
You should look at both if you are having
problems
5. Software
Software can be buggy, badly written, or
corrupted in some way
If it is buggy or badly written, you can look for
alternatives
If it is corrupted you can do a reinstallation
6. Top 1
This is a very useful tool to see what your
software is doing
Just open a terminal and type “top”
8. Top 3
This command lists all of the running processes
on your computer
It also shows how much CPU and memory
each one is using
You can sort the display by pressing an upper-
case letter “O”
For instance, the sequence upper-case “O”
-->n-->”enter” will sort by Memory used
10. Top 5
You want to look for processes that use a lot of
CPU or Memory as potential problems
Large numbers are not always a problem,
though. I have a Virtual Box VM open running a
Windows VM. That is an expected load that I
took into account.
But if Firefox is using 25% of your memory or
CPU, that is probably a problem
11. The kill test
One way you can test if a particular app is the
problem is to close it
Sometimes the app is not responding, so you
need to kill it
With top open in the terminal, type “k”
You will get an added prompt above the list of
processes asking which one you want to kill
Just enter the PID (process ID) of the process
12. KDE
If you use KDE you can bring up a system
monitor from krunner
Press Alt+F2 to bring up krunner
Click the second icon from the left, which looks
like a small graph
16. Note on Multi-Core Processors
Each process runs on a single core
Top, and the Gnome System Monitor report the
percentage of that single core that each
process uses
KDE's System Activity reports the percentage
of all processor cycles available on all cores, so
it reports a smaller number
Pay more attention to top, since maxing out a
single core is still a problem even if you have
another core available
17. Interpreting the results
If one process/application stands out, and
closing/killing it makes the problem go away,
you may have a software problem
You can then try to reinstall or find alternative
software
Solving a software problem may be a little work,
but it costs nothing. You should rule out
software problems before looking at a hardware
problem, therefore.
18. Hardware problems
There are potentially four problem areas:
CPU
RAM
Disk I/O
Video Card
Knowing the source of the problem will let you
resolve it without wasting money on unneeded
hardware upgrades
19. Where people go wrong
Many people will assume a sluggish computer
needs a CPU upgrade
More knowledgeable folks know that more RAM
is a lot more likely to work than a new CPU
In a PC World study (October 2010) RAM also
beat out a faster hard drive for improving
performance.
21. Load 1
Look at the load figures
They show the load over the past 1, 5, and 15
minutes
Load is the average number of processes that
have to wait for CPU time
You adjust for the number of cores. A load of 2
on a two-core system is equivalent to a load of
1 on a single-core system.
22. Load 2
Load is just one indication
You can get even more from the top command
Notice that the first line of the top results is the
same as you get from uptime
24. CPU Load 1
Look at the third line
Us is the percentage of CPU time taken up by
user processes. Note that user is not just a
person, it could be Apache, MySQL, etc. If this
is very high, it may be an indication of a high
CPU load.
Sy is the percentage used by the kernel and
other system processes
25. CPU Load 2
Id is the idle time. The higher the better here. If
this is reasonably high you can be pretty sure
you don't have a CPU problem.
Wa is the I/O wait time. This indicates the
percentage of time that the CPU was waiting for
I/O, which is usually your disk. A high number
here indicates a disk I/O problem, and might be
solved by getting a faster drive
For the others, try man top for an explanation
26. CPU Load 3
If you see a high number for us or sy, look at
the processes involved, like we did for software
You might see a high number related to a
particular application. That application may be
something you can fix or replace. But if it is
proper, like a high figure for MySQL on a
database or web server, you may need a better
CPU.
If it is a large number of separate processes
with no one being large, that is also an
indication that a new CPU is required
27. RAM
This is in fact the most common problem area,
and more RAM will often clear up any problem
you have
RAM is the workspace for the computer. All
code has to be copied into RAM before the
CPU can work with it.
When RAM runs out, code that may be less
frequently used gets copied to “swap”. This is
an area of reserved space on a disk.
28. Swap and RAM Performance
Because disk I/O is much slower than RAM,
code that is moved to swap is slower to access
If RAM is inadequate, code gets moved in and
out of the swap area constantly, causing “disk
thrashing”. This refers to constant hard drive
activity, which can often be heard or seen as a
flashing LED.
29. RAM Utilization
Do not worry if your RAM appears to be
completely utilized
This is not like a high percentage of CPU
utilization
RAM is supposed to be used, that is why it is
there
For instance, shared libraries are frequently
kept in RAM, which can speed up the launch of
other programs that use those libraries
30. RAM as Cache 1
To understand this, think of the RAM as a kind
of cache
Files in cache are always faster to access than
files on the hard drive
So the kernel will keep anything you have used
in RAM in case it is needed again
Any system that is used for a few hours will
almost certainly see all of the RAM in use
therefore
31. RAM as Cache 2
Because a lot of your RAM is being used as a
type of cache, that part of the RAM will be
released as needed
So if you start a new process and need more
RAM for it, some of the cached code is cleared
and the RAM is used for the new process
33. Interpreting RAM numbers
Note that line 4 is Mem
This shows that I have 16 GB of RAM
And almost all of it is used. Only 113MB is free
Is this a problem?
No, look at the next line for Swap
34. Swap in top
Look at line 5, Swap
There you see I have 6GB of swap space, but
only 1.7MB is being used. Almost all of my
swap space is empty.
Look at the cache number. This indicates how
much RAM is being used as a cache.
To see what is available here, look at cache
and free swap. In this case, there is 8GB of
cache, and 6GB of swap. No RAM problems
here!
35. Check RAM first
You want to check Swap issues before
checking other I/O issues because a RAM
problem can look like a disk I/O problem. This
is because the Swap is relying on disk I/O.
If you do have a RAM issue, look at the
processes to see which one(s) are responsible
Remember you can sort by memory used by
the sequence upper-case “O”
-->n-->”enter”
36. High RAM usage
Look for a process that uses an abnormally
high amount of RAM
This could be an indication of a memory leak
This is when an application does not release
memory when it is done, so that it gradually
uses up most of the available RAM
If you find this, look for an update that fixes it,
or look for an alternative
And if you find this, file a bug!
37. Disk I/O
The tool you want here is called iostat
This tool is not automatically installed, so you
may need to install it
You will probably find it in a package called
sysstat
Install this using your package manager
39. Iostat, the numbers
On the first line, you can see that I have a 2-
core CPU, I am using a 64-bit version of Linux,
and what kernel I am using
Then we get the same CPU numbers as the top
command gave us
The bottom section will give you the raw
numbers for disk I/O
40. The I/O numbers
Tps = transactions per second
Blk_read/s = blocks read per second
Blk_wrtn/s = blocks written per second
Blk_read = total blocks read
Blk-wrtn = total blocks written
41. Interpretation
Which drive is getting the activity? Does that
make sense?
In this case sda is getting most of the action
This is where my root partition is located, so all
of my kernel and system activity should be here
Sdb has my home partition. That gets less
activity since most of the time it is sitting idle.
42. Read vs. write
This can be a clue as well
Certain applications or processes can be
expected to require more reading or more
writing
Generally you should expect to have more
reads than writes
If you have your /var in its own partition, you
should see higher write numbers there than on
other partitions because of the logs being
written
44. Interpreting iotop
Here, instead of processes, you are looking at
threads
This could help uncover a thread that is
generating a lot of I/O activity
In this example, KDE's plasma desktop was on
top, and was writing to disk at 30 K/s
Does any thread consistently show up in the
top? Does this make sense?
45. Signs of video issues
The mouse is lagging
Try dragging a window across the screen, and
it does not move smoothly
Tearing
Slow or constant redraws
These can be caused by CPU issues as well,
so you want to eliminate that first
Misbehaving apps can cause this (e.g. Flash
plugins)
46. Summary
Before you spend money, do a systematic
troubleshoot
Test in the right order
Check software problems before hardware
problems
Always do video last since video artifacts can be
caused by CPU load
Look for results that point somewhere else, e.g. a
memory leak is really a software problem, not a
RAM problem