문제

I'm seeking algorithm to design multithreading application in java where each thread write data to db. I want to control the number of records written to db per second.

the application gets RPS (records per second) param and approximately generate those many load.

도움이 되었습니까?

해결책

If you can use external libraries, guava has a RateLimiter class which probably does what you ask for:

Rate limiters are often used to restrict the rate at which some physical or logical resource is accessed. This is in contrast to Semaphore which restricts the number of concurrent accesses instead of the rate.

다른 팁

You could create a BlockingQueue of permit objects and have an extra helper thread that adds RPS number of additional permits to the queue once per second. Writing threads block on the queue and do not write until they successfully pop a permit off the top of the queue.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top