Very infrequent posts about technology
Postgres Lock Queues, Migrations, and Timeouts
When Postgres operations obtain table-level locks, subsequent operations wait in a queue, but if there are any lock contentions in that queue, long-running queries have the potential to back everything up and can sometimes take down entire applications!
Read more...ActiveRecord take
vs first
ActiveRecord has a method called take
that returns a single record similar to first
, except take
doesn’t order the records before selecting one. This can GREATLY increase performance in some circumstances; the latency graph above shows a real-life example of take
significantly reducing the duration of an api call by changing a single first
to take
.
Numbered Block Params In Ruby
Ruby 2.7 added some syntax sugar that has been making my life easier at work; no longer do I need to use a
as my “placeholder” variable in enumerators, instead, we have a built in “numbered” block parameter!
Postgres Enums: Don’t Use ‘Em
While Postgres offers an ENUM type, the general recommendation is NOT to use it, here I discuss why and give an alterative solution that I prefer: creating a new table and referencing foreign keys
Read more...Using NOT
in Postgres CHECK
constraints
For some reason I could not find good information on this (maybe because it’s obvious). But you can add NOT
into your Postgres CHECK CONSTRAINT
s; this is particularly useful when you find a nice succinct way to express the negation of the constraint you want.
Ruby’s Partition Method: It Does What You Think.
Ruby has a neat function in Enumerable
called partition that can split the values in the enumerable into two partitions based arbitrary logic.
Cancelling PostgreSQL Queries When HTTP Request Times Out
During a recent effort at work to optimize database performance we found a bunch of queries which our Rails application triggered but, since the query took longer than our configured HTTP timeout, the transaction was later abandoned. We had initially thought that PgBouncer might have a setting to cancel queries after a request times-out, but that doesn’t seem to be a feature that PgBouncer Currently supports.
We want to cancel these queries to free-up database resources, especially in case we have db bottlenecks.
Read more...ufw
- Linux Firewall And How To Use It
08-02-2020: Updated with how I setup UFW on my home server
I’ve been tinkering a bit with Digital Ocean (use my referral link to get $100 in Digital Ocean credit) and I’ve decided to move a small personal project from Heroku to a droplet running a small Kubernetes (k8s) cluster. I want to do this both to learn about setting up k8s (very useful since I work with it daily) and because Digital Ocean is cheaper than Heroku for my use-case.
This will be the first post in a series about setting up this single-node k8s cluster on a Digital Ocean droplet; check out the do-k8s-node
tag to find the other posts in this series; I’ll also be adding links to the next post in the series as I write them.
This first post is about the firewall built into Ubuntu: ufw
as well as why I want to move from Heroku to Digital Ocean.
ActiveRecord.dup
and constantize
I’m still unsure how I want to use this blog and wether I intend on creating a separate section for these short “TIL” posts or if I want to keep them here, but for today I’m combining two TILs into a longer post. I’m also using this to experiment with a post not having an image associated with it; we’ll see if that bugs me and I end up changing it or not.
This week I’ve learned a bit about the limitations ActiveRecord’s dup
function as well as how constantize
works.
Some stuff about Active Record
A couple things about active record that I learned this week.
Read more...