-
Notifications
You must be signed in to change notification settings - Fork 62
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
add state to the group consumer #54
base: master
Are you sure you want to change the base?
Conversation
@dams This seems like something that's best handled in the consumer and outside of Kaffe. While I can see that there is a measure of convenience in having this maintained by Kaffe (your example fits nicely with things like Adding behavior like this to Kaffe would make it more complex and less focused, overall. I think we want to keep Kaffe focused on just doing the Kafka stuff. Please let me know if I'm not understanding; happy to discuss further! |
Thank you @objectuser for your swift reply ! I totally see your point, but I guess I'm not good enough in Elixir to see how I can achieve what you describe ("put your handle_messages function on a GenServer and maintain the state there") in an easy way. The way I use kaffe with my patch is to do exactly as you say: at init time, init_handler is called, it starts a genserver and returns its pid as handler_state. Now each time handle_messages is called, it gets the handle_state which is the associated genserver pid, and does a call to the genserver. It's nice and simple. What I need is one GenServer per partition, so one GenServer per group member worker. The only way I can see to implement this without my patch would be to store genservers pids in an ets table: each time handle_messages is called, check if for the current worker process (using self() ) there is a corresponding genserver in the ets table. If not, start_link a new genserver and store it in the ets table. I find this a bit clunky, but maybe it's just me. Do you have a better way of associating a worker with a genserver ? Thanks |
@dams I think that's basically the mechanics of it, yes. Although I think the Also, depending on your throughput requirements, you could simply create an |
Thanks for mentioning the Registry, it's something I might want to use indeed. I can't really afford having a bottleneck of an Agent or an ets table for storing the messages. The system I work with needs to aggregate messages with as little lag as possible, and the throughput is 1 TB per hour. So I need damn good parallelism. |
So, I've been using kaffe with this modification, and it has a lot of advantages. Among them:
So I was wondering if you'd accept this patch if I rewrite it to provide it as an option to the worker, or a different flavor. A bit like when using the simple consumer, the 'async' option makes it behave slightly differently. feedback welcome |
@dams We're discussing this a bit internally. |
Any progress ? |
I've thought about this a bit more. We would want to maintain backward compatibility by default. I wonder if we could introduce an abstraction somewhere around If the implementation could be swapped in, it could either be part of Kaffe, or just configured by the app. What do you think? |
I agree with keeping back compat by default. Not sure about using a behavior |
I need that for work. I've added an init_handler() function to define a state, which is passed around when handle_messages() is called. Of course it's not backward compatible so this should be reworked so that it's a new mode of consuming, instead of replacing the existing one. But I thouhgt I'd push that here now so I can get feedback.
Let me know if there is already a way to have a state being passed around, that I missed.
Thanks