Performance Tuning and Debugging Don Porter CSE/ISE 311: - - PowerPoint PPT Presentation

performance tuning and debugging
SMART_READER_LITE
LIVE PREVIEW

Performance Tuning and Debugging Don Porter CSE/ISE 311: - - PowerPoint PPT Presentation

CSE/ISE 311: Systems Administra5on Performance Tuning and Debugging Don Porter CSE/ISE 311: Systems Administra5on Why is my applica3on slow? No silver


slide-1
SLIDE 1

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Performance ¡Tuning ¡and ¡ Debugging ¡

Don ¡Porter ¡

slide-2
SLIDE 2

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Why ¡is ¡my ¡applica3on ¡slow? ¡

  • No ¡silver ¡bullet ¡
  • Part ¡science, ¡part ¡art ¡

– Science: ¡Measure ¡performance, ¡test ¡hypotheses ¡ – Art: ¡Finding ¡prac3cal ¡balances ¡of ¡concerns ¡

slide-3
SLIDE 3

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Most ¡common ¡culprits ¡

  • Insufficient ¡resources ¡
  • Configura3on ¡error ¡
  • Hardware ¡problems ¡
slide-4
SLIDE 4

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Digression: ¡Throughput ¡and ¡Latency ¡

  • What ¡are ¡they? ¡
  • Throughput: ¡Opera3ons ¡over ¡3me ¡

– Requests ¡per ¡second ¡ – Transac3ons ¡per ¡minute ¡ – Higher ¡is ¡beMer ¡

  • Latency: ¡Time ¡to ¡complete ¡one ¡opera3on ¡

– My ¡server ¡can ¡complete ¡an ¡HTTP ¡GET ¡in ¡.01 ¡seconds ¡ – Lower ¡is ¡beMer ¡

slide-5
SLIDE 5

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

What ¡happens ¡when ¡you ¡are ¡overloaded? ¡

0 ¡ 20 ¡ 40 ¡ 60 ¡ 80 ¡ 100 ¡ 120 ¡ 0 ¡ 25 ¡ 50 ¡ 75 ¡ 100 ¡ 125 ¡ 150 ¡ 175 ¡ 200 ¡

% ¡Maximum ¡Throughput ¡

Load ¡(%) ¡ Ideal ¡ Realis3c ¡

slide-6
SLIDE 6

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

What ¡happens ¡when ¡you ¡are ¡overloaded? ¡

0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 0 ¡ 25 ¡ 50 ¡ 75 ¡ 100 ¡ 125 ¡ 150 ¡ 175 ¡ 200 ¡

Latency ¡

Load ¡(%) ¡

Ideal ¡

Ideal ¡

slide-7
SLIDE 7

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

What ¡happens ¡when ¡you ¡are ¡overloaded? ¡

0 ¡ 100 ¡ 200 ¡ 300 ¡ 400 ¡ 500 ¡ 600 ¡ 0 ¡ 25 ¡ 50 ¡ 75 ¡ 100 ¡ 125 ¡ 150 ¡ 175 ¡ 200 ¡

Latency ¡

Load ¡(%) ¡ Ideal ¡ Realis3c ¡

Note ¡Change ¡in ¡Y ¡Axis ¡Scale-­‑-­‑-­‑approaches ¡infinity ¡

slide-8
SLIDE 8

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Graceful ¡Degrada3on ¡

  • Ideally, ¡when ¡a ¡system ¡is ¡overloaded, ¡by ¡n%, ¡
  • pera3on ¡latency ¡would ¡increase ¡by ¡n% ¡and ¡

throughput ¡would ¡stay ¡constant ¡

  • In ¡prac3ce, ¡systems ¡rarely ¡degrade ¡gracefully ¡when ¡

they ¡are ¡overloaded ¡

  • Thus, ¡finding ¡the ¡“limi3ng ¡factor” ¡is ¡essen3al ¡
slide-9
SLIDE 9

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

atop ¡

hMp://lwn.net/images/2010/atop/atopshot.png ¡

slide-10
SLIDE 10

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

atop ¡

  • Super-­‑useful ¡tool ¡that ¡shows ¡usage ¡of ¡ ¡

– CPU ¡ – Memory ¡ – Disk ¡ – Network ¡

  • On ¡a ¡color ¡terminal, ¡highlights ¡over-­‑used ¡resources ¡
slide-11
SLIDE 11

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

CPU ¡

  • Very ¡rarely ¡the ¡boMleneck ¡

– Actually ¡degrades ¡gracefully ¡in ¡most ¡cases ¡

  • Nonetheless, ¡overloaded ¡CPUs ¡will ¡seem ¡less ¡

responsive ¡

  • Note ¡that ¡when ¡another ¡resource ¡is ¡scarce, ¡CPU ¡3me ¡

is ¡used ¡trying ¡to ¡compensate ¡

slide-12
SLIDE 12

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Load ¡Average ¡

  • The ¡average ¡number ¡of ¡processes ¡wai3ng ¡for ¡the ¡

CPU ¡

– Less ¡than ¡1, ¡the ¡CPU ¡is ¡idle ¡ – Higher ¡than ¡1 ¡is ¡ok, ¡just ¡means ¡CPU ¡is ¡fully ¡u3lized ¡ – Very ¡high ¡values ¡(>8) ¡can ¡indicate ¡a ¡problem ¡

  • Read ¡from ¡the ¡up3me ¡command: ¡

$ uptime 20:10:13 up 20 days, 11:08, 5 users, load average: 0.00, 0.03, 0.05

slide-13
SLIDE 13

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Memory ¡

  • Oien ¡the ¡biggest ¡troublemaker ¡
  • Why? ¡

– OSes ¡over-­‑commit ¡memory ¡to ¡applica3ons ¡ – In ¡other ¡words, ¡if ¡I ¡have ¡1GB ¡RAM, ¡I ¡can ¡have ¡5 ¡ applica3ons ¡that ¡all ¡think ¡they ¡have ¡300 ¡MB ¡ – How ¡is ¡this ¡possible? ¡ – Swapping ¡

slide-14
SLIDE 14

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Swapping ¡

  • If ¡the ¡OS ¡is ¡running ¡low ¡on ¡memory, ¡it ¡can ¡take ¡RAM ¡

away ¡from ¡applica3ons ¡ ¡

– Save ¡the ¡contents ¡to ¡disk ¡ – Reuse ¡the ¡RAM ¡

  • If ¡the ¡applica3on ¡tries ¡to ¡read ¡or ¡write ¡to ¡this ¡

memory, ¡the ¡applica3on ¡is ¡interrupted, ¡OS ¡no3fied ¡

– OS ¡has ¡to ¡then ¡find ¡free ¡RAM, ¡replace ¡contents ¡for ¡app ¡

slide-15
SLIDE 15

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

The ¡problem ¡with ¡swapping ¡

  • Disk ¡reads ¡and ¡writes ¡are ¡slow ¡(rela3ve ¡to ¡CPU) ¡

– You ¡very ¡rarely ¡wait ¡for ¡them ¡before ¡making ¡progress ¡ – Except ¡when ¡swapping ¡

  • Mi3ga3on: ¡OS ¡makes ¡educated ¡guesses ¡about ¡

unlikely-­‑to-­‑be-­‑used ¡data ¡to ¡swap ¡out ¡

– In ¡the ¡best ¡case, ¡things ¡slow ¡down ¡a ¡bit, ¡and ¡then ¡return ¡to ¡ normal ¡

  • In ¡the ¡worst ¡case, ¡data ¡ping-­‑pongs ¡between ¡disk ¡and ¡

RAM ¡

– Called ¡thrashing ¡

slide-16
SLIDE 16

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Recommenda3on ¡

  • If ¡you ¡see ¡substan3al ¡swap ¡usage ¡in ¡atop, ¡buy ¡more ¡

RAM ¡

– It ¡is ¡cheap, ¡and ¡more ¡RAM ¡is ¡cheaper ¡now ¡than ¡when ¡you ¡ bought ¡the ¡computer ¡

  • Note: ¡OS ¡oien ¡uses ¡substan3al ¡amount ¡of ¡RAM ¡to ¡

cache ¡the ¡file ¡system ¡contents, ¡so ¡don’t ¡be ¡mislead ¡if ¡ total ¡RAM ¡usage ¡is ¡near ¡100% ¡

– Look ¡at ¡swap ¡to ¡detect ¡insufficient ¡RAM ¡

slide-17
SLIDE 17

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

In ¡a ¡crisis… ¡

  • Linux ¡has ¡an ¡out-­‑of-­‑memory ¡killer ¡
  • As ¡adver3sed, ¡it ¡just ¡kills ¡programs ¡un3l ¡there ¡is ¡

enough ¡memory ¡

slide-18
SLIDE 18

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Swappiness ¡

  • Linux ¡tries ¡to ¡swap ¡some ¡data ¡out ¡before ¡there ¡is ¡a ¡

crisis ¡

  • Linux ¡has ¡a ¡parameter ¡that ¡sets ¡how ¡aggressively ¡to ¡

swap ¡data. ¡ ¡This ¡can ¡get ¡out ¡of ¡whack ¡

– /proc/sys/vm/swappiness ¡

  • I’ve ¡personally ¡had ¡to ¡dial ¡this ¡back ¡on ¡an ¡Ubuntu ¡

release ¡that ¡set ¡the ¡default ¡too ¡high, ¡in ¡order ¡for ¡a ¡ nearly ¡idle ¡system ¡to ¡be ¡usable ¡

slide-19
SLIDE 19

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Network ¡

  • When ¡the ¡network ¡is ¡overloaded, ¡packets ¡are ¡

dropped ¡

– But ¡the ¡other ¡end ¡usually ¡retries ¡

  • Two ¡biggest ¡culprit ¡for ¡network ¡overload: ¡

– AMack ¡(denial ¡of ¡service, ¡brute-­‑force ¡password ¡guessing, ¡ spam, ¡etc) ¡ – Legi3mate ¡overload ¡(slashdoMed ¡website, ¡peak ¡usage ¡ 3me) ¡

  • Need ¡to ¡figure ¡out ¡which ¡
slide-20
SLIDE 20

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Network ¡advice ¡

  • If ¡the ¡overload ¡is ¡not ¡legi3mate, ¡good ¡security ¡

prac3ce ¡can ¡help ¡to ¡reduce ¡wasteful ¡traffic ¡

– Firewall, ¡denyhosts, ¡spam ¡filter, ¡etc. ¡ – For ¡DoS, ¡there ¡are ¡also ¡quality-­‑of-­‑service ¡tools ¡on ¡many ¡ network ¡devices ¡to ¡limit ¡the ¡share ¡of ¡packets ¡delivered ¡ from ¡any ¡one ¡source ¡

  • If ¡the ¡overload ¡is ¡legi3mate, ¡you ¡may ¡need ¡more ¡

servers ¡and ¡a ¡load-­‑balancer ¡

– Like ¡round-­‑robin ¡DNS ¡

slide-21
SLIDE 21

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Disks ¡

  • Very ¡rarely ¡the ¡boMleneck, ¡except: ¡

– (Implicitly ¡when ¡thrashing ¡swap) ¡ – Actual ¡disk-­‑intensive ¡workloads ¡(e.g., ¡database) ¡ – And ¡when ¡disk ¡is ¡nearing ¡end-­‑of-­‑life ¡

  • Why ¡rarely ¡a ¡problem? ¡

– Most ¡disk ¡requests ¡are ¡asynchronous ¡ – Most ¡disk-­‑intensive ¡applica3ons ¡inherently ¡rate-­‑limited ¡

  • Why ¡a ¡problem ¡at ¡end-­‑of-­‑life? ¡

– Heavy ¡remapping ¡yields ¡poor ¡scheduling ¡ – For ¡SSDs, ¡internal ¡bookkeeping ¡can ¡take ¡longer ¡as ¡the ¡ device ¡ages ¡

slide-22
SLIDE 22

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Disks ¡

  • In ¡general, ¡if ¡the ¡disk ¡is ¡gemng ¡old, ¡the ¡best ¡advice ¡is ¡

replace ¡it ¡

– You ¡also ¡don’t ¡want ¡to ¡lose ¡data ¡

  • Some ¡file ¡systems ¡perform ¡worse ¡as ¡they ¡age, ¡but ¡

these ¡are ¡increasingly ¡uncommon ¡

– Running ¡a ¡“defragmenter” ¡can ¡help ¡

slide-23
SLIDE 23

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

General ¡advice ¡

  • Measure ¡a ¡performance ¡baseline ¡for ¡your ¡system ¡

– Applica3on ¡performance ¡ – Microbenchmarks ¡(e.g., ¡lmbench) ¡

  • If ¡things ¡seem ¡slower, ¡re-­‑measure ¡the ¡component ¡

– Has ¡my ¡disk ¡bandwidth ¡degraded? ¡

  • This ¡is ¡the ¡science ¡of ¡tuning ¡
slide-24
SLIDE 24

CSE/ISE ¡311: ¡Systems ¡Administra5on ¡

Other ¡tools ¡

  • /proc/cpuinfo, ¡/proc/meminfo, ¡/proc/diskstats ¡– ¡

useful ¡system ¡sta3s3cs ¡

– Lots ¡of ¡goodies ¡in ¡/proc ¡

  • vmstat ¡– ¡more ¡details ¡on ¡memory ¡usage ¡
  • nice/renice ¡– ¡adjust ¡scheduling ¡priority, ¡giving ¡more ¡

CPU ¡3me ¡to ¡important ¡applica3ons ¡

  • swapinfo ¡– ¡more ¡details ¡on ¡swapping ¡
  • netstat ¡– ¡more ¡details ¡about ¡network ¡usage ¡
  • hdparm/sdparm ¡– ¡measure ¡raw ¡disk ¡performance ¡
  • iostat ¡– ¡more ¡details ¡about ¡disk ¡I/O ¡