DroidB2

DroidB2

Broadway SQS delivery time longer than expected

Hello, I am not sure the problem is in the library, but maybe you could help me in what way should i research.
We use broadway_sqs library for amazon sqs.
we measure time to deliver for each message separately on the application side. Time to deliver may be up to 20 seconds!
So the question is, what may it take so long?
[{“delivered”:0.0},{“delivered”:6.0},{“delivered”:10.0},{“delivered”:10.0},{“delivered”:9.0},{“delivered”:9.0},{“delivered”:10.0},{“delivered”:9.0},{“delivered”:9.0},{“delivered”:10.0},{“delivered”:10.0},{“delivered”:9.0},{“delivered”:11.0},{“delivered”:10.0},{“delivered”:9.0},{“delivered”:11.0}]

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Right, so at a minimum if you aren’t sending more than 10 messages you’ll have a wait time of at least 2 seconds, since that’s the batch timeout. The other delays you mentioned of up to 20 seconds sound a lot like the max value for the SQS wait_time_seconds option. You aren’t setting it explicitly, but the queue itself will also have a default. What is the queues ReceiveMessageWaitTimeSeconds value?

burntham

burntham

We have observed the same thing, especially when we only have 1 or 2 messages being sent to the queue every now and then.

For us the issue was broadwaySQS’s default polling (short polling) and receive_interval (5 seconds).
The default behaviour sees a broadway producer polling sqs for messages and on an empty receive, waiting 5 seconds before trying again.

If there are very few messages in the queue short polling does not guarantee you will get any messages since it only queries a subset of the servers that make up your SQS queue. That means it can take multiple attempts to get a single message. In our case, that meant our broadway producer would take between 2 and 60 seconds to receive a message when there was only 1 enqueued.

We needed the best response time possible and were able to achieve it by reducing the receive_interval to 50 ms and setting the wait_time_seconds to 20.
Note: for receive_interval doesn’t seem necessary with long polling and we wanted the value close to 0, but it would probably work with 0.
for wait_time_seconds: any number above 0 enables long polling SQS long polling docs. Long polling is guaranteed to not return an empty receive if there are any messages in the queue and it will return as soon as any messages are available.

For example:

producer: [
        module: {
          BroadwaySQS.Producer,
          queue_url: Keyword.get(config, :queue_url), config: Keyword.get(config, :credentials), 
          wait_time_seconds: 20
          receive_interval: 50
        },
      ],

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement