0% found this document useful (0 votes)
109 views26 pages

Optimizing Linux Performance

Optimizing Linux performance is important to ensure applications run efficiently on various hardware, save users time, and provide high quality service. There are many tools available to analyze CPU, memory, I/O, network, and process-specific performance, and identify issues. These include vmstat, top, iostat, sar, strace, and others. Issues can then be isolated and addressed, such as optimizing code, memory, startup time, I/O usage, or network usage.

Uploaded by

Mous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views26 pages

Optimizing Linux Performance

Optimizing Linux performance is important to ensure applications run efficiently on various hardware, save users time, and provide high quality service. There are many tools available to analyze CPU, memory, I/O, network, and process-specific performance, and identify issues. These include vmstat, top, iostat, sar, strace, and others. Issues can then be isolated and addressed, such as optimizing code, memory, startup time, I/O usage, or network usage.

Uploaded by

Mous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Optimizing Linux Performance

Why is Performance Important


•  Regular desktop user
–  Not everyone has the latest hardware
–  Waiting for an application to open
–  Application not responding
–  Memory errors
–  Extra kernel paging
•  Efficient application simply runs on more
systems, is usable by more people
Contd…
•  Do more work with fewer resources
•  Run on older hardware
•  Save users time
•  Higher quality of service for more users
•  Need to be a detective to find performance
issues, not a hardcore programmer
Linux
•  Unprecedented access to source code v/s
proprietary windows
•  Has powerful performance tools
–  Not centralized however
–  Some are distro standardized
–  Most tools are freelanced
–  Specific tool for specific task
–  Multiple tools for same task
Performance Investigation
•  Find a metric, baseline, and target
–  What is the current system performance?
–  What should it be?
•  Webserver example
–  How many page requests per second does it serve?
–  How many should it be serving?
•  Find a similar configured system that performs
well and compare
Contd…
•  Track down the approximate problem
•  See whether problem has already been
solved
–  Bug report results
–  Mailing lists
–  Email the developer
Contd…
•  Isolate the problem
•  Run same performance tool on a good
system and yours and compare
•  Change one thing at a time
•  Have a changelist with results
•  Always re-measure after optimizing
–  Make sure no new problems crop up
Performance information: CPU
•  Run Queue statistics
–  Processes competing for CPU time
–  I/O blocks
–  Load average
•  Context switches
–  Kernel scheduling
•  Interrupts
–  /proc/interrupts
•  CPU Utilization
Performance Tools: CPU
•  Vmstat (Virtual Memoy Statistics)
–  # processes, CPU utilization, # interrupts, # context switches

Oprofile:Details of CPU utilization


•  Top:Swiss army knife of system monitoring
•  Other top options:
–  d = Delay
–  n = iterations
–  i = do not display processes that are not using any of the cpu
•  Procinfo – cleaner output than vmstat
Other procinfo options:Procinfo
-f runs in full screen
-d displays statistics change between samples rather than totals
-n sec Number of seconds to stop between each sample
•  Gnome-system-monitor (graphical)
•  Mpstat (Multiprocessor statistics)

options
–  Mpstat –p {cpu | all}
–  Mpstat delay
•  Sar (System Activity Reporter)
Stores information in a binary file to be replayed later
Performance Information: Memory
•  Memory subsystem (Virtual memory)
•  Swapd
–  Total amount of memory currently swapped to disk.
•  Buffers and Cache
–  Too Much physical memory
•  Active v/s Inactive memory
–  Managing paging
•  Processor and high v/s low memory
–  32 bit addressing more than 1 gb of memory
Performance Tools: Memory
•  Vmstat
–  Swap information, memory free and used
•  Top
–  Run time toggles sort via memory
•  Procinfo
–  Paging information
•  Free
–  How is the system using memory
•  Slabtop
–  Kernel allocated caches and how full they are
•  Sar
•  /proc/meminfo
Performance Information: Process
specific CPU
•  Application runtime
–  Kernel or user or library routines
–  Application profiling
•  Kernel time v/s user time
•  Library time v/s application time
•  Subdividing application time
•  Ps
–  Dynamic process information

–  Other options
–  -A all options
–  -e all processes
–  r only running processes etc…
Performance Tools: Process Specific
CPU
•  Time
–  Can be used with the application switch
•  Strace
–  Trace system calls of an application
•  Ltrace
–  Trace library calls of an application
•  Gprof
–  Profile applications (overhead issue, needs to recompile)
•  Oprofile
–  Profile applications – process level sampling
Performance Information: I/O
•  Total amount and type (read/write) of disk
I/O on a system
•  Which devices are servicing most of the
disk
•  Effectiveness of a disk responding to I/O
requests
•  Which processes are using a given set of
files
Performance Tools: I/O
•  Vmstat
–  Block/sector read/write information
•  Iostat
–  Per device, per partition breakdown
•  Sar
–  Lesser functionality than iostat but can simultaneously
record many different types of statistics
•  Lsof
–  Which processes use which file
Performance Information: Network
•  Speed and duplex settings of interfaces
•  Amount of network traffic over each interface
•  Types of IP traffic flowing in and out of the
system
•  Amount of each type of IP traffic
•  Which applications are generating IP traffic
Performance Tools: Network
•  Mii-tool and ethtool - Interface configuration
information
•  Ifconfig - Configuration and Packet information
•  Ip - Performance statistics
•  Sar - Detailed network information
•  Gkrellm - Graphical real time monitor
•  Iptraf - Specific monitoring
•  Netstat - Sockets and packet information
•  Etherape - Network connection information
Optimizing an application
•  Memory
•  Is memory usage a problem?
–  Top or ps
–  What type of memory is it using?
–  Cat /proc/<pid>/status
–  Large VmStk? Use gdb and find out which function is using most
of the stack
–  Large VmExe? Use nm and remove large symbol code
–  Large VmLib? Use /proc/<pid>/map and streamline large library
usage
–  Can also use memory profiler of the programming language
Contd…
•  Start up time
•  Is application start up time slow?
–  Is loader the problem? Use ld and reduce the
number and size of libraries linked
–  Large CPU usage? Use gprof or oprofile to
measure critical functions repeatedly
–  Add switches to speed up after looking at
gprof information or edit code
Contd…
•  I/O
•  Is the disk usage a problem?
–  Run iostat and look for overload
–  Spread these files to multiple disks
–  Which function is causing large amount of
disk I/O?
–  Which files are accessed most? Use strace
and track system calls, spread this evenly
between disks or a faster disk
Contd…
•  Network
•  Is network usage a problem?
–  Use ethtool and check the interface limit
–  Use iptraf and look at the traffic
–  Use ifconfig to check for packet errors
–  Use netstat and find out which application is using
that port and generating traffic
–  Use strace and find out which application socket is
responsible for the traffic

You might also like