mmmrrr

mmmrrr

I tested reverse proxying implementations of different technologies on my local development machine and I noticed that the different Elixir Variants I tried add significant (as in: measurable) overhead to the request.

Just as an example, in Haskell I used http-reverse-proxy which came closest to what I need from a performance for feature ratio.

What I basically want to achieve is: read a session cookie, validate some stuff and inject data into the request and then pass it on (read: proxy authentication).

My Elixir implementation tests used :reverse_proxy_plug and a self grown controller method that just sets of a new Http request:

%HTTPoison.Response{
      body: body,
      headers: headers,
      status_code: status
    } = HTTPoison.get!("http://localhost:3000/" <> tail)

After inspecting, :reverse_proxy_plug the implementations seem fairly similar. Of course this approach is naive and it is not suprising that the request will take at least twice the time of the other solutions I tested since I basically have the overhead of two HTTP requests.

So:

  1. Is there a usable, high performance reverse proxy in Elixir (or Erlang) that I could peek at?
  2. Is there any chance to use such a solution while keeping all the niceties of Plug and/or Phoenix.Router?
  3. (meta) If the answer to 1. is no: can someone recommend resources on the basics of reverse proxying?

(Nota bene: the difference in my, admittedly basic, tests was ~16ms vs. ~4ms and only the Elixir solutions showed that behaviour, for the other implementations (esp. Rust and Haskell) the overhead was not measurable in ms)

Related, but old topic:

Showing Posts 1 to 7

entone

entone

We use Ambassador as in ingress gateway on k8s. Ambassador has a hook for authentication, every request basically hits a separate service, our elixir service, just cowboy and plug, passing only the headers. We do some basic “auth” and ip checking, all the backing data sits in a local ETS table, maybe moving to persistent terms eventually. We see an average of 100 microseconds overhead per request.

acrolink

acrolink

I recommend having a look at Nginx and Lua.

mmmrrr

mmmrrr OP

Hey thanks for your answers!

@entone that’s interesting. But if I understand your setup correctly, all the http lifting is done by ambassedor, which calls a service that returns something and then hands the request to the next target in the chain, correct? If so, it is a little different to what I’d like to achieve since I’d want to have cowboy forward the request directly.

@acrolink thanks for the suggestion. I know about OpenResty. I could use it but it increases the complexity of the system significantly. Also it gets harder to decide what to implement where, since you could theoretically completely replace the Elixir stack with it. And then I could also just use Haskell, Go, Rust, etc. and relearn new framework semantics from scratch.

So what I’m after is more of a “what is Nginx doing that makes it so efficient to use as a reverse proxy and how can we emulate that behavior in Elixir”.

(And hopefully: here is how Mr./Mrs. Niceperson has done it in the past in Erlang/Elixir :smiley:)

entone

entone

Yeah, that makes sense. But there’s no reason you can’t get really low latency. But as soon as you start reaching out to external services you’re at the mercy of the network and downstream services. Keep as much local as possible. Persistent terms and ets are your friends :wink:

It might also be worth looking at using something like Mint to manage the downstream/proxy connections. It’s process-less, so could save you a bit of overhead and use the same incoming request process to handle the proxy connection.

Are you serializing/deserializing anything at the proxy level? Other than headers?

mmmrrr

mmmrrr OP

I don’t think I need to process more than the headers…

Mint looks really promising. I’ll check out if using it helps in my situation. But use the same incoming request process to handle the proxy connection sounds like the exact thing I want to achieve. :slight_smile:

ityonemo

ityonemo

Definitely listening to this space. There’s a place in my deployment where I’ll need to proxy a one-way encrypted https inbound connection to a two-way encrypted https connection. I can do this with nginx but I’m a little bit scared about reloading nginx configs when I need to dynamically add a new route, (Maybe that’s silly). I know it should be possible in elixir, but am curious as to why or why not use the BEAM as a reverse proxy.

mmmrrr

mmmrrr OP

So I tried a few more things and it really seems that the best solution is reverse_proxy_plug (read: the naiive approach of starting a new httpoison request).

I would say one could probably achieve better results by utilizing mint, but the amount of work necessary is significant. So what I’ll do is: start with this slow(ish) approach and optimize once this starts to become a real problem in production…

Thanks for all the input, everyone :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews