If a lot of message are produced on kakfa and if I try to consume (using python confluent_kafka library) and process them, the database (working on mysql DB) gets loaded with a lot of queries quickly. I want to slow down the consuming speed based on the load on the DB. I was thinking of using time.sleep() in the consumer loop. This way I can provide a larger time to sleep if there is a load on the DB. I will be fetching the number of seconds to sleep from redis key. Similary will change the value of the redis key when there is a certain amount of load on the db. Like set the value of key to 30s if db load > 80 % or something like that.
I am stuck on how I can calculate the load on the DB.
Also is there a another way of controlling the consuming speed, then please tell.