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

Use semaphore-like permits for some actor operations #906

Merged
merged 7 commits into from
Mar 21, 2022

Conversation

bplommer
Copy link
Member

@bplommer bplommer commented Mar 15, 2022

This was supposed to be a demo but I got a bit carried away - inspired by #903

@bplommer
Copy link
Member Author

bplommer commented Mar 15, 2022

Looking into this, some actor operations delegate to other actor operations, pushing them to the back of the queue - I wonder if that could be the cause of some of the odd race conditions we've seen?

No I don't think so - the only code in the actor that pushes requests to the actor is for offset commits, which aren't themselves invoked via the actor.

@bplommer bplommer changed the title Demo of semaphore permits from consumer actor Use semaphore-like permits for most actor operations Mar 15, 2022
@bplommer
Copy link
Member Author

Oops, I broke something somewhere along the line 😬

@bplommer bplommer changed the title Use semaphore-like permits for most actor operations Use semaphore-like permits for some actor operations Mar 15, 2022
@bplommer bplommer marked this pull request as ready for review March 15, 2022 14:30
@bplommer bplommer requested a review from vlovgr March 15, 2022 14:30
@LMnet
Copy link
Member

LMnet commented Mar 16, 2022

I checked these changes briefly. They may be good by itself, but I talked about a different approach: I wanted to completely get rid of a KafkaConsumerActor. We don't need it actually. We could call а java consumer from the fs2.kafka.KafkaConsumer through semaphore without KafkaConsumerActor.

To create polling we could run a fiber that uses the same semaphore and the same java consumer and run this fiber in the background.

@bplommer
Copy link
Member Author

I agree that would be preferable as an end state, but I think the changes in this PR make direct progress towards it: the code that calls permit could directly switch to using a cats-effect semaphore.

One thing about using a single semaphore that may be an issue is that it would be strictly FIFO rather than the current approach that distinguishes polls from other requests - that said, I’m not sure the current approach is actually correct. What I thought we were currently doing, and what seems right, is to always handle all pending requests before doing a poll, but what actually seems to happen is that once the request queue is drained the actor will block until the next poll, and only after the next poll will it process requests that happened after the queue was drained. @vlovgr can you clarify what the intended behaviour is?

@vlovgr
Copy link
Contributor

vlovgr commented Mar 17, 2022

Ideally, we should process all fetch requests before polling, since partitions without fetch requests will remain paused when polling (as you note, we aren't really doing exactly that today). If it makes a difference in practice versus just processing everything FIFO is difficult to say. The only contract we really have to adhere to is to ensure poll is called at least every max.poll.interval.ms.

@bplommer
Copy link
Member Author

Is there any objection to merging these changes as a step towards using a semaphore for everything?

@bplommer bplommer merged commit 36c2882 into fd4s:series/2.x Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants