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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
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
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews