import com.google.common.util.concurrent.RateLimiter

val rateLimiter = RateLimiter.create(Double.MAX_VALUE)

fun main(args: Array<String>) {
..
	rateLimiter.setRate(rate)
..
}


fun acquireTest(transaction: Int) {
	for (i in 1..transaction) {
		val delayed = rateLimiter.acquire()
		println("acquire() ${LocalDateTime.now()} idx:$i delayed:$delayed")
	}
}

fun tryAcquireTest(transaction: Int, sleep: Long) {
	for (i in 1..transaction) {
		val permit = rateLimiter.tryAcquire()
		if (!permit)
			Thread.sleep(sleep)
		println("tryAcquire() ${LocalDateTime.now()} idx:$i delayed:${!permit}")
	}
}




acquire() 2020-02-07T01:03:43.529 idx:1 delayed:0.0
acquire() 2020-02-07T01:03:43.532 idx:2 delayed:0.0
acquire() 2020-02-07T01:03:43.532 idx:3 delayed:0.0
acquire() 2020-02-07T01:03:43.532 idx:4 delayed:0.0
acquire() 2020-02-07T01:03:43.532 idx:5 delayed:0.0
acquire() 2020-02-07T01:03:43.533 idx:6 delayed:0.0
acquire() 2020-02-07T01:03:43.533 idx:7 delayed:0.0
acquire() 2020-02-07T01:03:43.533 idx:8 delayed:0.0
acquire() 2020-02-07T01:03:43.533 idx:9 delayed:0.0
acquire() 2020-02-07T01:03:43.534 idx:10 delayed:0.0
acquire() 2020-02-07T01:03:43.534 idx:11 delayed:0.0
acquire() 2020-02-07T01:03:43.559 idx:12 delayed:0.015218
acquire() 2020-02-07T01:03:43.587 idx:13 delayed:0.016563
acquire() 2020-02-07T01:03:43.617 idx:14 delayed:0.028709
acquire() 2020-02-07T01:03:43.650 idx:15 delayed:0.031712
acquire() 2020-02-07T01:03:43.685 idx:16 delayed:0.03272
acquire() 2020-02-07T01:03:43.717 idx:17 delayed:0.030847
acquire() 2020-02-07T01:03:43.752 idx:18 delayed:0.032155
acquire() 2020-02-07T01:03:43.783 idx:19 delayed:0.030739
acquire() 2020-02-07T01:03:43.816 idx:20 delayed:0.032224
acquire() 2020-02-07T01:03:43.850 idx:21 delayed:0.0327
acquire() 2020-02-07T01:03:43.883 idx:22 delayed:0.032775
acquire() 2020-02-07T01:03:43.918 idx:23 delayed:0.032504
acquire() 2020-02-07T01:03:43.949 idx:24 delayed:0.031472
acquire() 2020-02-07T01:03:43.983 idx:25 delayed:0.033536
acquire() 2020-02-07T01:03:44.016 idx:26 delayed:0.032604
acquire() 2020-02-07T01:03:44.050 idx:27 delayed:0.032683
acquire() 2020-02-07T01:03:44.083 idx:28 delayed:0.032741
acquire() 2020-02-07T01:03:44.116 idx:29 delayed:0.032735
acquire() 2020-02-07T01:03:44.149 idx:30 delayed:0.032772
acquire() 2020-02-07T01:03:44.183 idx:31 delayed:0.032826
acquire() 2020-02-07T01:03:44.216 idx:32 delayed:0.032863
acquire() 2020-02-07T01:03:44.250 idx:33 delayed:0.032883
acquire() 2020-02-07T01:03:44.283 idx:34 delayed:0.032582
acquire() 2020-02-07T01:03:44.316 idx:35 delayed:0.032601
acquire() 2020-02-07T01:03:44.351 idx:36 delayed:0.032636
acquire() 2020-02-07T01:03:44.382 idx:37 delayed:0.031093
acquire() 2020-02-07T01:03:44.416 idx:38 delayed:0.033184
acquire() 2020-02-07T01:03:44.449 idx:39 delayed:0.033249
acquire() 2020-02-07T01:03:44.482 idx:40 delayed:0.033331
acquire() 2020-02-07T01:03:44.518 idx:41 delayed:0.033397
acquire() 2020-02-07T01:03:44.549 idx:42 delayed:0.030999
acquire() 2020-02-07T01:03:44.583 idx:43 delayed:0.033003
acquire() 2020-02-07T01:03:44.616 idx:44 delayed:0.033054
acquire() 2020-02-07T01:03:44.649 idx:45 delayed:0.033136
acquire() 2020-02-07T01:03:44.683 idx:46 delayed:0.033069
acquire() 2020-02-07T01:03:44.716 idx:47 delayed:0.033076
acquire() 2020-02-07T01:03:44.749 idx:48 delayed:0.033109
acquire() 2020-02-07T01:03:44.782 idx:49 delayed:0.033198
acquire() 2020-02-07T01:03:44.816 idx:50 delayed:0.033254
tryAcquire() 2020-02-07T01:03:44.916 idx:1 delayed:true
tryAcquire() 2020-02-07T01:03:44.916 idx:2 delayed:false
tryAcquire() 2020-02-07T01:03:44.916 idx:3 delayed:false
tryAcquire() 2020-02-07T01:03:44.916 idx:4 delayed:false
tryAcquire() 2020-02-07T01:03:45.017 idx:5 delayed:true
tryAcquire() 2020-02-07T01:03:45.017 idx:6 delayed:false
tryAcquire() 2020-02-07T01:03:45.017 idx:7 delayed:false
tryAcquire() 2020-02-07T01:03:45.017 idx:8 delayed:false
tryAcquire() 2020-02-07T01:03:45.121 idx:9 delayed:true
tryAcquire() 2020-02-07T01:03:45.121 idx:10 delayed:false
tryAcquire() 2020-02-07T01:03:45.121 idx:11 delayed:false
tryAcquire() 2020-02-07T01:03:45.121 idx:12 delayed:false
tryAcquire() 2020-02-07T01:03:45.221 idx:13 delayed:true
tryAcquire() 2020-02-07T01:03:45.222 idx:14 delayed:false
tryAcquire() 2020-02-07T01:03:45.222 idx:15 delayed:false
tryAcquire() 2020-02-07T01:03:45.222 idx:16 delayed:false
tryAcquire() 2020-02-07T01:03:45.327 idx:17 delayed:true
tryAcquire() 2020-02-07T01:03:45.327 idx:18 delayed:false
tryAcquire() 2020-02-07T01:03:45.328 idx:19 delayed:false
tryAcquire() 2020-02-07T01:03:45.328 idx:20 delayed:false
tryAcquire() 2020-02-07T01:03:45.428 idx:21 delayed:true
tryAcquire() 2020-02-07T01:03:45.428 idx:22 delayed:false
tryAcquire() 2020-02-07T01:03:45.428 idx:23 delayed:false
tryAcquire() 2020-02-07T01:03:45.428 idx:24 delayed:false
tryAcquire() 2020-02-07T01:03:45.530 idx:25 delayed:true
tryAcquire() 2020-02-07T01:03:45.531 idx:26 delayed:false
tryAcquire() 2020-02-07T01:03:45.531 idx:27 delayed:false
tryAcquire() 2020-02-07T01:03:45.531 idx:28 delayed:false
tryAcquire() 2020-02-07T01:03:45.631 idx:29 delayed:true
tryAcquire() 2020-02-07T01:03:45.631 idx:30 delayed:false
tryAcquire() 2020-02-07T01:03:45.631 idx:31 delayed:false
tryAcquire() 2020-02-07T01:03:45.632 idx:32 delayed:false
tryAcquire() 2020-02-07T01:03:45.732 idx:33 delayed:true
tryAcquire() 2020-02-07T01:03:45.732 idx:34 delayed:false
tryAcquire() 2020-02-07T01:03:45.732 idx:35 delayed:false
tryAcquire() 2020-02-07T01:03:45.733 idx:36 delayed:false
tryAcquire() 2020-02-07T01:03:45.833 idx:37 delayed:true
tryAcquire() 2020-02-07T01:03:45.833 idx:38 delayed:false
tryAcquire() 2020-02-07T01:03:45.834 idx:39 delayed:false
tryAcquire() 2020-02-07T01:03:45.834 idx:40 delayed:false
tryAcquire() 2020-02-07T01:03:45.934 idx:41 delayed:true
tryAcquire() 2020-02-07T01:03:45.934 idx:42 delayed:false
tryAcquire() 2020-02-07T01:03:45.934 idx:43 delayed:false
tryAcquire() 2020-02-07T01:03:45.934 idx:44 delayed:false
tryAcquire() 2020-02-07T01:03:46.035 idx:45 delayed:true
tryAcquire() 2020-02-07T01:03:46.035 idx:46 delayed:false
tryAcquire() 2020-02-07T01:03:46.035 idx:47 delayed:false
tryAcquire() 2020-02-07T01:03:46.035 idx:48 delayed:false
tryAcquire() 2020-02-07T01:03:46.135 idx:49 delayed:true
tryAcquire() 2020-02-07T01:03:46.135 idx:50 delayed:false
----
acquire()    setRate:30.0 transactionCount:50 elapsedSec:1.629 actualTps:30.693677102516883
tryAcquire() setRate:30.0 transactionCount:50 elapsedSec:1.319 actualTps:37.90750568612585 sleepMs:100


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2020-02-07 01:10:45
Processing time 0.0068 sec