Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQS: Long polling on empty queue makes other pollers wait #2888

Open
logicaleap opened this issue Aug 3, 2022 · 2 comments
Open

SQS: Long polling on empty queue makes other pollers wait #2888

logicaleap opened this issue Aug 3, 2022 · 2 comments

Comments

@logicaleap
Copy link

logicaleap commented Aug 3, 2022

Version

AkkaHttpVersion = "10.2.9"
AlpakkaVersion = "3.0.4"

Scenario

Create two SQS pollers, one per queue.

Config:

        SqsSourceSettings settings = SqsSourceSettings.create()
                .withWaitTime(Duration.ofSeconds(10))
                .withMaxBatchSize(10)

Queue A has 10,000 messages
Queue B has 0 messages

Message processing blocks for about 100ms.

       CompletableFuture.supplyAsync(() -> handleSqsMessage(pollRequest, msg), workerDispatcher 
                // uses a "blocking dispatcher"
        );

Expected behaviour:

Both queues are polled concurrently and messages flow continuously when available

Actual behaviour

  1. Some messages are polled from queue A
  2. Polling stalls on queue A while waiting 10 seconds for queue B to complete polling
  3. Repeat

Workaround

  • Set wait time to zero
  • Close on empty receive (to avoid hammering SQS API)
  • When stream closes on empty receive for queue B, delay next poll by 10 seconds
        SqsSourceSettings settings = SqsSourceSettings.create()
                .withWaitTime(Duration.ofSeconds(0))
                .withCloseOnEmptyReceive(true);

       streamCompletion.thenAccept(done -> {
                actorSystem.scheduler().scheduleOnce(Duration.ofSeconds(SQS_POLL_INTERVAL_EMPTY_RECEIVE), sender, pollingRequest, getContext().dispatcher(), getSelf());
            }
@logicaleap logicaleap changed the title Long polling on empty queue makes other pollers wait SQS: Long polling on empty queue makes other pollers wait Aug 3, 2022
@logicaleap
Copy link
Author

The issue is with akka.stream.alpakka.sqs.impl.BalancingMapAsync
Setting SqsSourceSettings.withParallelRequests to a value other than 1 uses that class, which slows things down

@logicaleap
Copy link
Author

This 'fixes' long polling, but causes other issues - message delays.

Even with parallelRequests=1, Alpakka seems to open two connections to AWS.

  1. Calls ReceiveMessage, processes messages
  2. Calls ReceiveMessage, ignores messages

Because request #2 ignores messages, they become invisible, and only available after visibilityTimeout expires.
At that point, the message is either received (by 1st connection), or ignored (by 2nd connection). If ignored, it triggers invisibility again.

Can you please advise some workarounds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants