How to waste less money with AWS

First of all, you need to carefully select the region where you are going to establish your servers.

US-EAST / US-WEST-2 were the cheapest regions at the time I wrote this.

You can check the prices per region in the links at the end of this post.

How to waste less money with AWS

While using AWS for almost a year on the Free Tier, I didn’t pay attention to instance purchasing options.

Choosing the right AWS region alongside Reserved capacity, Savings Plans, Spot Instances for fault-tolerant jobs, and ARM64 AWS Graviton instance families can cut monthly compute bills significantly without sacrificing reliability.

Pricing references: Amazon EC2 Pricing | EC2 Purchasing Options

How to change the timezone in Ubuntu

How to change the timezone in Ubuntu

To change the timezone interactively in Ubuntu, run:

sudo dpkg-reconfigure tzdata

On modern systemd-based Ubuntu releases, you can also set it non-interactively with timedatectl:

sudo timedatectl set-timezone America/Sao_Paulo
timedatectl status

How to survive with an AWS EC2 t1.micro instance

amazon-ec2

With my t1.micro, I can host my personal Redmine, Git, and blog, which I couldn’t do with the default settings.

I used a swap file for it, and here is how you can set it up:

Copy & paste the code below:

sudo dd if=/dev/zero of=/var/swapfile bs=1M count=2048 status=progress
sudo chown root:root /var/swapfile
sudo chmod 0600 /var/swapfile
sudo mkswap /var/swapfile
sudo swapon /var/swapfile
echo '/var/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

To disable it cleanly later, run:

sudo swapoff -v /var/swapfile
sudo rm /var/swapfile
sudo sed -i '\|/var/swapfile|d' /etc/fstab

Alongside swap, keeping a tiny VM responsive came down to caching and restraint: placing Varnish in front of Apache absorbed static/anonymous reads before spawning memory-heavy worker processes, while PHP bytecode caching (APC back then, replaced natively by PHP OPcache today) avoided recompiling scripts on every request.

Cloud & Modern Linux Caveats: Heavy swapping on network-attached EBS volumes adds latency and burns through storage IOPS burst credits, so keep vm.swappiness=10 and treat swap strictly as an OOM safety net. On modern Linux kernels, compressed in-memory swap with zram is much faster and avoids unnecessary disk writes, while older tools like prelink are deprecated because of ASLR.

Zabbix

Zabbix

Very cool tool for sysadmins! Check it out! 🙂 https://www.zabbix.com/

With lightweight agents, SNMP polling for routers and switches, flexible triggers, and auto-discovery, Zabbix is still one of my go-to open-source tools for monitoring Linux servers and network hardware.

Android Virtual Device (aka AVD) tuning

Android Virtual Device (aka AVD) tuning

In order to make the Android emulator run faster and be more responsive, you can configure it to take advantage of hardware acceleration, using a combination of configuration options, specific Android system images and hardware drivers…

My AVD API 18 config has an Intel processor, 768 MB RAM + 128 MB VM Heap + Host GPU + Intel HAXM.
My AVD API 10 config has an Intel processor, 768 MB RAM + 128 MB VM Heap + Intel HAXM.

Modern Note: On modern setups, Android Studio replaced Eclipse ADT, and KVM (on Linux) or the Android Emulator Hypervisor Driver (AEHD) (on Windows) superseded Intel HAXM. Hardware GPU acceleration is still what matters most for smooth frame rates.

CLI Database optimization

CLI Database optimization

MariaDB & MySQL:

sudo apt install default-mysql-client   # or: mariadb-client
mysqlcheck -h yourdatabasehost -u root -p --auto-repair --check --all-databases
mysqlcheck -h yourdatabasehost -u root -p --auto-repair --optimize --all-databases
# Note: MariaDB 11+ also provides mariadb-check; --optimize rebuilds InnoDB tables, so schedule on busy databases carefully.

PostgreSQL:

vacuumdb -afvz -h yourdatabasehost -U postgres
reindexdb -a -h yourdatabasehost -U postgres

Updated (November 4, 2021): Docker example:

docker exec -it postgres-server vacuumdb -afvz -U postgres

Amazon Web Services: Free Tier

Amazon Web Services: Free Tier

How do you get started with AWS for free?
Just go to https://aws.amazon.com/free/ and create your account.
A credit card is required, even for a free account.

Historical Context (2013): When this article was written, AWS Free Tier offered t1.micro instances with 613 MB of RAM. Modern AWS Free Tier accounts provide t2.micro / t3.micro instances (1 GB RAM) for 12 months plus selected Always Free allowances (such as DynamoDB and AWS Lambda).

What can you do with the free account?
It’s up to you! If you are building a light-traffic website, the Free Tier can handle it. 🙂

You can have up to two EC2 instances (1 Linux, 1 Windows) with 613 MB of RAM and up to 30 GB of EBS storage. You can use all 30 GB on a Linux instance, which is the best way to spend your “free” resources (Windows is memory-hungry).

You can have up to one RDS instance (PostgreSQL, MySQL, …) with 20 GB of database storage and 20 GB for backups.

You can use Amazon S3 with up to 5 GB of storage and up to 20k PUT and 20k GET requests.

You can have up to one Memcached node with 213 MB of RAM.

And a few other services (ELB, DynamoDB, SNS, CloudWatch, …).

Continue reading

Check your website performance

Check your website performance

WebPageTest, GTmetrix, PageSpeed Insights, and Website Grader can test your website and web server and help you see if you are using optimal configurations!

GNU/Linux CLI image optimizer

GNU/Linux CLI image optimizer

There are major speed benefits to image optimization using optipng for PNGs, gifsicle for GIFs, and jpegoptim for JPEGs. Optimized graphics transfer faster and improve perceived load times. Below, optipng and gifsicle optimize PNG/GIF files losslessly, whereas adding --max=85 or ImageMagick -quality 80 applies bounded lossy compression to JPEGs (omit --max=85 if you only want lossless metadata stripping).

Ubuntu / Debian:

sudo apt update && sudo apt install optipng gifsicle jpegoptim imagemagick

Run these commands inside the target directory as the user who owns those images (note the quoted '*.ext' globs so the shell never expands them prematurely):

find . -type f -iname '*.png' -exec optipng -o7 --strip all {} \;
find . -type f -iname '*.gif' -exec gifsicle -O2 -b {} \;
# Strictly lossless JPEG strip:
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec jpegoptim --strip-all {} \;
# Optional bounded lossy + progressive pass for web assets:
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec jpegoptim --strip-all --max=85 {} \;
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec convert -interlace line -quality 80 {} {} \;

For WordPress automation, you can install EWWW Image Optimizer or convert assets to WebP/AVIF.