-
Notifications
You must be signed in to change notification settings - Fork 679
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
New Feature: asyncio support for BinLogStreamReader #593
Comments
@gongyisheng |
Hi @sean-k1 , To meet guarantee of order of messages, we need to use a memory queue (I used asyncio.Queue here) to store message temporarily. Another coroutine reads data from memory queue and send data to kafka. In this case, the memory queue can help order the messages. I can help add an example to show how to run async code safely.
The biggest reason to do this is to make this package compatible with asyncio. As asyncio gain popularity after python 3.8, we have more 3p libs and workload that uses asyncio to run I/O processes concurrently to make full use of cpu resource. http requests, redis client, database client, message queue client, s3... a lot of popular libs that has I/O operations have asyncio support. Here's the benefits I see:
Thanks again, let me know if you have more questions! We can also have a survey to see if there's more ppl want asyncio support. |
@gongyisheng However the change you suggested - especially in your code - isn't technically within the scope of MySQL replication client. Are you suggesting that we should go beyond existing implementation and extend our responsibility? |
Hi @dongwook-chan, thank you for your feedback. I think providing an async class of BinLogStreamReader is inside the responsibility of mysql replication client. |
@gongyisheng Could you clarify which part of BinLogStreamReader should be async? The code you provided will work even without incorporating async to BinLogStreaReader. |
@dongwook-chan Yeah the code I provide can work but it doesn't work in a smooth way because it's not async. The event loop may be blocked in the middle because I suggest that we can make |
@gongyisheng I have a few questions that I want to ask just because I want to know how the community uses the package and how they can benefit from asyncio.
|
Hi @dongwook-chan, sorry I was a bit buzy this month, coming to reply
Merry Christmas! |
Not sure if you are aware but a fork exists: I'm big fan of asyncio and I can see the benefits if you have if you need with a slow operation like S3 in the same process. |
@julien-duponchelle Yes I'm a big fan of asyncio too. |
@julien-duponchelle @gongyisheng |
Hi python-mysql-replication community, I want to request asyncio support for BinLogStreamReader.
My use case here is to use BinLogStreamReader to receive binlog message and forward it to a message queue and a consumer will process it. Here's an example of my code:
Due to the fact that BinLogStreamReader
__iter__
method is blocking, it blocks the asyncio event loop and causes some side effects, eg.And I see the examples like https://github.com/julien-duponchelle/python-mysql-replication/blob/main/examples/mysql_to_kafka.py, it's a common use case to have a forward service to listen binlog stream and forward it to somewhere else.
Currently the package does not support asyncio. I think asyncio is a fit for this package because reading binlog is I/O process and asyncio allows parallel processing for multiple I/O process. There's also open source 3p lib that supports asyncio like aiomysql, aiokafka so I think there're use cases to have asyncio support. For order guarantee, as long as we continue to use iterator interface it will not cause message disorder issues.
Let me know your idea!
The text was updated successfully, but these errors were encountered: