Premature Optimization is the Root of all Evil

„premature optimization is the root of all evil.”
— Sir Tony Hoare, popularized by Donald Knuth

Yes, it caught up with me as well ;)

I was playing around with Terrible (Terraform and Ansible) to deploy some SW on a libvirt environment, basically to learn stuff. But starting the domain (VM) for the first time, bootstrapping from a cloud-init ISO and updating all packages took way too long for my taste.
Being young and stupid (*ahem*), I jumped to the conclusion that the yum update was just too slow and I needed to speed it up.

First things first, you can’t see improvement, if you don’t measure. So let’s take a baseline:

terraform apply -auto-approve  1.53s user 0.42s system 0% cpu 3:52.50 total

3 minutes 53 seconds. This get’s annoying over time. So the „brilliant” idea I had was to set up a squid caching proxy in order to locally provide the rpms files needed for the updates, thus cutting down on the yum update time.

So I started up a squid docker image, after some debugging created a squid.config that worked, opened the necessary firewall ports and modified my cloud-init configuration so that yum would use my caching proxy.

 - 'echo "proxy=" >> /etc/yum.conf'
 - 'echo "proxy=" >> /etc/yum.conf'
Test again, first time:
terraform apply -auto-approve  1.31s user 0.33s system 0% cpu 3:54.64 total

As expected, no improvement. But now, the second time:

terraform apply -auto-approve  1.35s user 0.32s system 0% cpu 3:56.31 total

Damn! Why u so slow? After some another espresso, I noticed that yum is talking to different mirrors, which the proxy interprets as a new request and can’t use the cache for. So, next iteration. I reconfigure yum via my cloud-init in such a way, that one mirror close to me will be used for all request.

Prime the cache, and then, the second run:

terraform apply -auto-approve  1.35s user 0.29s system 0% cpu 3:55.84 total

This is getting worse the better. Why? Well now I took the time to actually take a look at /var/log/message while the cloud-init code was running. And low and behold, the yum update I thought was the bottleneck was a tiny fraction of the actual runtime. As I am already running on SSDs, the only change I was able to make was to enable host-passthrough for the libvirt CPU configuration and adding more CPUs (MORRR POWER !!!!!). With that I finally ended up at:

terraform apply -auto-approve  1.30s user 0.31s system 0% cpu 3:10.39 total

What actually improved performance was me adding and resetting snapshots of the domain (VM) inside my Ansible playbooks so I had quick turnaround-cycles for debugging a setup issue later in the chain.

Repeat after me: premature optimization is the root of all evil (although you learn new stuff while doing that).

Tagged as: , , , , , | Author:
[Montag, 20220905, 15:43 | permanent link | 0 Kommentar(e)

Comments are closed for this story.


„Leyrers Online Pamphlet“ ist die persönliche Website von mir, Martin Leyrer. Die hier veröffentlichten Beiträge spiegeln meine Ideen, Interessen, meinen Humor und fallweise auch mein Leben wider.
The postings on this site are my own and do not represent the positions, strategies or opinions of any former, current or future employer of mine.

Me, Elsewhere

Tag Cloud

2007, 2do, a-trust,, a1, accessability, acta, advent, age, amazon, ankündigung, apache, apple, audio, austria, backup, barcamp, basteln, bba, big brother awards, birthday, blog, blogging, book, books, browser, Browser_-_Firefox, bruce sterling, buch, bürgerkarte, cars, cartoon, ccc, cfp, christmas, cloud, collection, command line, commandline, computer, computing, concert, conference, copyright, covid19, css, database, date, datenschutz, debian, delicious, demokratie, design, desktop, deutsch, deutschland, dev, developer, development, devops, digitalks, dilbert, disobay, dna, dns, Doctor Who, documentation, domino, Domino, Douglas Adams, download, downloads, drm, dsk, dvd, e-card, e-government, e-mail, e-voting, E71, Ein_Tag_im_Leben, elga, email, encryption, essen, eu, event, events, exchange, Extensions, fail, fedora, feedback, film, firefox, flash, flightexpress, food, foto, fsfe, fun, future, games, gaming, geek, geld, git, gleichberechtigung, google, graz, grüne, grüninnen, hack, hacker, handtuch, handy, hardware, HHGTTG, history, how-to, howto, hp, html, humor, IBM, ibm, ical, iCalendar, image, innovation, intel, internet, internet explorer, iphone, ipod, isp, IT, it, java, javascript, job, journalismus, keyboard, knowledge, konzert, language, laptop, law, lego, lenovo, life, links, Linux, linux, linuxwochen, linuxwochenende, live, living, lol, london, lost+found, lotus, Lotus, Lotus Notes, lotus notes, lotusnotes, LotusNotes, Lotusphere, lotusphere, Lotusphere2006, lotusphere2007, Lotusphere2008, lotusphere2008, lustig, m3_bei_der_Arbeit, mac, mail, marketing, mathematik, media, medien, metalab, microsoft, Microsoft, mITtendrin, mobile, mood, movie, mp3, multimedia, music, musik, männer, nasa, netwatcher, network, netzpolitik, news, nokia, Notes, notes, Notes+Domino, office, online, OOXML, open source, openoffice, opensource, orf, orlando, os, outlook, patents, pc, pdf, performance, perl, personal, php, picture, pictures, podcast, politics, politik, pr, press, presse, privacy, privatsphäre, productivity, programming, protest, public speaking, qtalk, quintessenz, quote, quotes, radio, rant, recherche, recht, release, review, rezension, rip, rss, science, search, security, server, settings, sf, shaarli, Show-n-tell thursday, sicherheit, silverlight, SnTT, social media, software, sony, sound, space, spam, sprache, spö, ssh, ssl, standards, storage, story, stupid, summerspecial, sun, surveillance, sysadmin, talk, talks, technology, The Hitchhikers Guide to the Galaxy, theme, think, thinkpad, thunderbird, tip, tipp, tools, topgear, torrent, towel, Towel Day, TowelDay, travel, truth, tv, twitter, ubuntu, ui, uk, unix, update, usa, usb, vds, video, videoüberwachung, vienna, Vim, vim, vintage, vista, vorratsdatenspeicherung, vortrag, wahl, wcm, web, web 2.0, web2.0, Web20, web20, webdesign, werbung, wien, wiener linien, wikileaks, windows, windows 7, wired, wishlist, wissen, Wissen_ist_Macht, wlan, work, workshops, wow, writing, wtf, wunschzettel, Wunschzettel, www, xbox, xml, xp, zensur, zukunft, zune, österreich, övp, übersetzung, überwachung

AFK Readinglist