andyleclair

andyleclair

Hi all, I’m quite pleased to be open-sourcing a project that @cabol and I have been working on, PartitionedBuffer. It’s a performant and flexible write buffer that we’ve found useful in a number of scenarios.

Currently, we’re shipping it with two buffer implementations, PartitionedBuffer.Queue and PartitionedBuffer.Map. Queue is useful for buffering any write that comes in (think: I need to buffer writes to, e.g. Clickhouse, because Clickhouse wants large blocks of inserts, not individual writes). Map is useful for scenarios where you may have data that changes very frequently but you want to debounce writes to a downstream service (think: I need to update some value every unit time, last write wins).

I’m happy to answer any questions in this thread. Enjoy, I hope it makes your life a little easier!

Hex: PartitionedBuffer — PartitionedBuffer v0.4.2
Github:

https://github.com/appcues/partitioned_buffer

Showing Posts 1 to 6

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Is this fire and forget from the standpoint of the calling process? Or is there to wait until it ACKs?

Tangentially with respect to Clickhouse have you looked at server side buffering with its native async inserts?

andyleclair

andyleclair OP

Yes. So, imagine it as a replacement for Task.Supervisor.async_nolink for fire-and-forget tasks. If you’re creating many fire-and-forget tasks, you will most definitely notice the overhead of creating and GC-ing the processes at a certain level of load, and if you get a flood of traffic, you’d spike the number of processes which could lead to OOMkills, etc. PartitionedBuffer solves that problem.

PartitionedBuffer isn’t designed for backpressure per-se, so if you have a downstream service that’s getting overloaded, it won’t save you from that. We do rebuffer if we have transient failures but we are lucky that our service has pretty predictable scaling and we have a lot of monitoring in place. Obviously if you’ve got a catastrophic failure, this won’t save you, you’ll have to deal with it yourself :wink:

We have looked into async writes for Clickhouse, but there are several gotchas there, and we find it easier to solve problems on our end. We have excellent primatives in the BEAM to deal with it, so that’s what we do.

We also use the Map buffer quite a bit as well to debounce hot keys and to handle tasks that need to run e.g. once per-user on some schedule, but users to process come in irregularly. We had a system that would run a GenServer per-user but we had issues where a large influx of users we hadn’t seen before could crash the service because so many processes got spawned. We were regularly running 10-20 servers to handle this workload, now we can happily work 4 servers at ~100% CPU and they’re completely stable.

garrison

garrison

Batching on the client is always going to have less overhead because you’re amortizing the cost of each request. (You are probably aware of this.)

Library looks great btw!

andyleclair

andyleclair OP

Yes! We actually don’t use this library for writing to Clickhouse in prod (we use it for buffering writes to Kafka, then we stream from Kafka into Clickhouse – some ETL needed), it was just a convenient example

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I’ll resist the urge to dive into a whole Clickhouse digression because we have been doing a lot with it lately.

As far as the buffer is concerned are you processing data where data loss in the case of a crash is acceptable or is there an ACK mechanism where a caller can get confirmation its data was written out and flush the value on its end?

andyleclair

andyleclair OP

Implying we let the BEAM crash :wink:

We don’t have a mechanism built-in where, e.g. a caller process could register to be notified when a flush occurs, because we usually have our flush interval on the order of several seconds (depending on the process), but you could build something like that yourself. The flush callback is just a function that receives a batch of messages (chunked) and you could store the pids of callers somewhere and send them a message when you’ve flushed. We just don’t? Our system takes data in over websocket and we’re pretty latency-sensitive on responses, since we’re returning content to be displayed inside and on top of our customers’ sites.

We monitor our systems pretty tightly and we have a lot of headroom RAM-wise on our instances (we run r7g.8xl in prod for our biggest workload). The only instance we’ve seen the BEAM crash are OOM conditions and we simply don’t let that happen. We have proactive systems in place that restarts the BEAM process if some precondition is met (ram usage, run queue, etc.) to protect against this, and we trap exits to make sure we finish processing work when the process terminates. We have verified this works in prod (and we deploy several times daily sometimes, so it gets exercised frequently).

That said, what we’re putting in there isn’t like, payments data, it’s behavioral analytics data (think clickstream-type data) but we do trust that this system works

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
pferriby
Introductory paragraph I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews