Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <vector>
#include <string>
#include <mutex>
#include <future>
#include <chrono>
#include <utility>
#include <assert.h>
#include <pthread.h>
@chanks
chanks / gist:7585810
Last active July 19, 2024 10:16
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell
module Printf
%default total
data Format = FInt Format -- %d
| FString Format -- %s
| FOther Char Format -- [a-zA-Z0-9]
| FEnd --
format : List Char -> Format
@stesie
stesie / index.html
Created April 1, 2016 22:28
AWS IoT-based serverless JS-Webapp Pub/Sub demo
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>AWS IoT Pub/Sub Demo</title>
</head>
<body>
<h1>AWS IoT Pub/Sub Demo</h1>
<form>
<button type="button" id="connect">connect!</button>
@warmfusion
warmfusion / README.md
Last active June 4, 2021 14:50
Notes from building ETCD / Confd / Haproxy autoconfiguration environment

The following documents a trial of using etcd, and confd to automatically configure a haproxy load balancer.

It is built using a combination of blogs, resources and experimentation, but provides a rough template of the approach that would allow a fully featured balancer to be configured from etcd keyvalues.

TODO

  • Include systemd sidekick unit to automatically register the key's into ETCD based on a docker service (for example) being started
  • A more complete haproxy template that builds a valid, complex haproxy that would be capable of dealing with Future PLC's balancer requirements
@tmspzz
tmspzz / install-haskell-stack-arm.sh
Last active April 28, 2019 07:00
A scrip to install Haskell Stack and set up things properly on Raspbian
#!/bin/sh
# Update: As of March 24th 2017 this script won't work.
# The script at https://get.haskellstack.org/ is broken
# because the binary of Stack 1.4 for ARM is missing from https://www.stackage.org/stack/ .
# You can still get the binary for Stack 1.3.2 from
# https://github.com/commercialhaskell/stack/releases/download/v1.3.2/stack-1.3.2-linux-arm.tar.gz
# and place it at $USR_LOCAL_BIN/stack in your system.
# Once Stack is installed you can proceed with the Install LLVM step

Using nc and protoc as protobuf client and server

Inspiration: Linux and Unix nc command

Example protobuf definition:

message Person {
  required string name = 1;
  required int32 id = 2;
@3noch
3noch / phpWith.nix
Created March 28, 2017 21:18
PHP with configuration in Nix
{ pkgs ? import <nixpkgs> {}
, phpPackage ? pkgs.php
, phpPackages ? pkgs.phpPackages
, opCache ? false
, showErrors ? false
, extensions ? []
, zendExtensions ? []
, extraConfig ? ""
}:
let
@jaburns
jaburns / genindex.cpp
Last active March 10, 2023 18:10
Generational indices in C++ vs Rust
/*
Copyright 2021 Jeremy Burns
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR O