Absinthe.Subscription.publish performance

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.

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.

1 Like

Thanks for confirming Ben!

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?

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.

1 Like