June 2023 Archives

Cloud Provider Price Performance Comparison: Spot VMs

In my recent Cloud Comparison, I mentioned that I'd look at Spot VM pricing in an update. This is the update - 6 out of the 10 providers tested offer Spot/Preemptible instance pricing.

At SpareRoom we make some good use of Spot VMs. E.g. our perl test suite gets to run on fast VM types at very low cost: currently we are using c3-highcpu-22 instances which normally come at $0.95/hour each. The spot pricing for them is more than 10x lower, at just $0.086/h. At these prices, if our test suite needed it (it's already fast), we'd be able to launch c3-highcpu-176 (176 vCPUs) at well under $1/h!

Profiling Perl under Apache

At SpareRoom we still use Apache/mod_perl and, despite Devel::NYTProf::Apache's warnings about it not being maintained, it is still the best way for profiling Perl.

All you need to do really, for a mod_perl app, is to include this in your Apache config:

PerlPassEnv NYTPROF # Not needed for default settings.
PerlModule Devel::NYTProf::Apache

You should also allow a single worker/child, and make sure it terminates cleanly before processing the output (nytprofhtml).

Since I want my dev/test environments to normally run with multiple workers and no profiler attached, I have a bash alias that exits apache and restarts it set-up for profiling. I thought I'd share an example of that, as I find it very useful.

First, a basic example pulled from what I used on our older CentOS/RedHat VM:

profile_apache() {
  systemctl stop httpd.service
  grep -q -F 'PerlModule Devel::NYTProf::Apache' /etc/httpd/conf/httpd.conf \
    || echo 'PerlModule Devel::NYTProf::Apache' >> /etc/httpd/conf/httpd.conf
  sed -i 's/^#PerlModule Devel/PerlModule Devel/g' /etc/httpd/conf/httpd.conf
  echo "Starting apache to collect profile data. Ctrl+c once to end."
  httpd -X
  echo "Restarting apache and creating html report."
  sed -i 's/^PerlModule Devel/#PerlModule Devel/g' /etc/httpd/conf/httpd.conf
  systemctl start httpd.service &
  echo "Profile report in nytprof/index.html"

It's mostly self-explanatory, the profile_apache command will shut down apache, add the PerlModule directive to the config if it's not there (or uncomment it) and launch an attached single worker instance of apache. It will wait until you send a SIGINT (e.g. press ctrl+C) before restoring/relaunching apache to the original configuration and producing the profiler report.

Now, if you have Debian/Ubuntu, you'd have to modify a bit. And if you are running on docker and sed -i gives you Device or resource busy errors (for trying to change mounted file inode from within container), you can use a method that copies instead of modifying in-place, such as sed -ci.

The alias becomes:

profile_apache() {
  apache2ctl stop && sleep 1
  grep -q -F 'PerlModule Devel::NYTProf::Apache' /etc/apache2/mods-available/perl.conf \
    || echo -e "\nPerlModule Devel::NYTProf::Apache" >> /etc/apache2/mods-available/perl.conf
  sed -ci 's/^#PerlModule Devel/PerlModule Devel/g' /etc/apache2/mods-available/perl.conf
  source /etc/apache2/envvars
  echo "Starting apache to collect profile data. Ctrl+c once to end."
  apache2 -X
  echo "Restarting apache and creating html report."
  sed -ci 's/^PerlModule Devel/#PerlModule Devel/g' /etc/apache2/mods-available/perl.conf
  apache2ctl start &
  echo "Profile report in nytprof/index.html"

This is the basic idea, although my alias does some extra things like putting the report in an apache-mounted directory and providing a browser link, removing the PerlRequire that preloads our .pm modules (it clashes with NYTProf) etc.

PS, <code> does not work on the bash code above (adds some colours, but renders everything in a single wrapping line with the regular font), so I had to use <pre>. If someone knows how to fix it (tried markdown ``` as well), I can add syntax highlighting - for now I cross-posted to dev.to to make it look right.

About Dimitrios Kechagias

user-pic Computer scientist, physicist, amateur astronomer.