Urgent.News

What's breaking now, across thousands of outlets.

Tech

How I Put PgCache in Front of a 16-Million-Row Postgres Database

Disclaimer: This is a side project, not a production story. The slow-query problem is real, but the database is synthetic data I generated to make it show up on demand. I have no connection to PgCache. Everything here is in a repo you can clone and run. I tested version 0.6.2. A handful of dashboard queries on one of my projects were fine for a year and then weren't: count users by tier, revenue…

A developer tested PgCache, a proxy that caches database reads, in front of a 16-million-row Postgres database. The purpose was to compare PgCache's performance against a properly tuned Postgres database. To set up the test, the developer cloned a GitHub repository, configured Docker Compose to run two containers - one for the original Postgres on port 5433, and another for PgCache on port 5432.

The PgCache container kept its cache in shared memory, which required at least twice the shared_buffers size. The developer then ran a benchmark test, executing four queries - point lookup by id, count users by tier, revenue by country, and top products per category - 150 times each with a concurrency level of 10. Both the original database and PgCache served the queries, but PgCache significantly reduced the query times from hundreds or thousands of milliseconds to under one millisecond.

The developer also tested PgCache's ability to handle updates - inserting a new enterprise user directly into the original Postgres database. PgCache's cached count updated almost immediately after the insertion, showing that the cache remained consistent with the latest data. The first ninety seconds of the test were slower as PgCache was syncing with the Postgres database, but after that, the cached reads were almost instantaneous, demonstrating the efficiency of PgCache in reducing query times.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Tim Cook’s Departure Memo on His Last Day as CEO

Tim Cook: There is something truly special about Apple. I am most proud of what an annual report could never capture. This place is proof that culture triumphs over everything.

  • Tim Cook expressed pride in Apple's unique culture in his departure memo.
  • Cook emphasized the importance of Apple's culture in driving their success.
  • Cook's memo revealed a sense of gratitude and humility in his private self.

Fuel Prices Increased Again

The federal government has decided to increase the price of motor spirit (MS) petrol and high-speed diesel (HSD) for the … Read More The post Fuel Prices Increased Again appeared first on ProPakistani…

More from Tuesday 1 September →