aloukissas

aloukissas

When doing a publish call, should we expect the performance behavior to be similar to PubSub.broadcast/4 (i.e. almost instant)? Reading through the Absinthe code, it looks like that perhaps the run_docset call may be expensive.

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @aloukissas publish is indeed expensive by design, it is not instant like broadcast. Unlike broadcast which merely needs to send a message to various processes, Absinthe needs to execute the documents associated with a topic before it can send results to end users. So some process somewhere needs to bear the cost of performing this execution.

By default, that is the process that triggers the publish call, generally a mutation. This operates as a form of back pressure, where load incurred by an operation on the system is felt by the request that triggers that load.

aloukissas

aloukissas OP

Thanks for confirming Ben!

aloukissas

aloukissas OP

Should we expect to see better performance on the mutation if instead of doing out-of-band call to publish, we use the trigger functionality like in the example in the docs?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

No trigger just runs the publish call inside of middleware on the mutation same as calling publish. You can spawn a task and call publish inside the task, or (better) you could build like an oban job queue of publish calls perhaps. The main danger to just spawning tasks is that you overload and potentially even OOM the system if you have many subscribers and many mutations on those subscribers without any backpressure.

aloukissas

aloukissas OP

Following up here: we are noticing that Absinthe.Subscription.Local.publish_mutation/3 can often be very spiky wrt latency, sometimes hitting > 1 second. The resolvers involved are instantaneous: they use the provided payload and optionally Nebulex in-memory cache (in the microseconds).

Here’s the interesting part: we see huge gaps in the traces between when the publish_mutation is called until the resolvers are called (i.e. when the [:absinthe, :subscription, :publish, :start] and [:absinthe, :subscription, :publish, :stop] telemetry events are emitted. This span can e.g. take 50 msec yet the entire publish/3 span can take 10-20x that, in unaccounted for time.

If I’m reading the code correctly, the code below is what’s run before (gh link):

      for {field, key_strategy} <- subscribed_fields,
          {topic, doc} <- get_docs(pubsub, field, mutation_result, key_strategy) do
        {topic, key_strategy, doc}
      end

This calls Registry module underneath.. I wonder if under pressure this can have performance issues?

hubertlepicki

hubertlepicki

@aloukissas not sure if this is applicable in your case, or you can make it applicable, but I found a tremendous performance improvement after deduplication subscription resolvers Understanding Subscriptions — absinthe v1.11.0

Subscriptions by default are expensive because they have to be resolved in context of each connected user. You can pass a context to it and make it resolve only once.

That not always can be applied, obviously if different users should see different data it often can’t work.

aloukissas

aloukissas OP

I learned this the hard way when I first started using Absinthe with subs. Dedup should be the default, things don’t really work at all without it.

hubertlepicki

hubertlepicki

That’s a broader topic about GraphQL in general and subscriptions share the same possible negative implications for performance as the protocol in general.

I kinda use them as a pubsub mechanism these days, and use it to notify that something changed rather than sending the big payload in subscription. That helps too, especially if the client then can batch up debounce their own API calls to fetch the updated data.

If you keep the subscriptions simple, and keep the Graph tree flat / two levels max with no loops, GraphQL is pretty nice.

aloukissas

aloukissas OP

TBH, using subs as a signaling system is wrong. There is something in absinthe subscriptions that does not work well under load. We’ve forked it and added a ton more instrumentation to help us identify these.

gabrielpra

gabrielpra

Hey @aloukissas! Did you find anything useful through your instrumentation?

I have found this comment about context size that could be relevant, but haven’t started digging too deep yet: Absinthe cannot seem to handle even 1000 concurrent subscriptions - #2 by josevalim

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews