-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper script to benchmark rate limiting
This script needs to be piped into bin/console on the api vm.
- Loading branch information
1 parent
72b4189
commit 611396d
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# usage: pipe this script into bin/console on the api vm | ||
# this script logs to stderr, thus you might want to redirect stdout to /dev/null | ||
|
||
NUM_USERS = 1000 | ||
NUM_REQUESTS_PER_USER = 1000 | ||
|
||
logger = Logger.new($stderr) | ||
|
||
rate_limiter = CloudFoundry::Middleware::RateLimiter::EXPIRING_REQUEST_COUNTER | ||
rate_limiter_v2 = CloudFoundry::Middleware::RateLimiterV2API::EXPIRING_REQUEST_COUNTER | ||
service_broker_rate_limiter = CloudFoundry::Middleware::ServiceBrokerRateLimiter::CONCURRENT_REQUEST_COUNTER | ||
reset_interval_in_minutes = 60 | ||
max_concurrent_requests = 10 | ||
|
||
logger.info("Creating #{NUM_USERS} random user guids...") | ||
user_guids = [] | ||
NUM_USERS.times do | ||
user_guids << SecureRandom.uuid | ||
end | ||
logger.info(' ... done.') | ||
|
||
logger.info('Running benchmark...') | ||
result = Benchmark.measure do | ||
NUM_REQUESTS_PER_USER.times do |i| | ||
user_guids.each do |user_guid| | ||
rate_limiter.increment(user_guid, reset_interval_in_minutes, logger) | ||
rate_limiter_v2.increment(user_guid, reset_interval_in_minutes, logger) | ||
service_broker_rate_limiter.try_increment?(user_guid, max_concurrent_requests, logger) | ||
service_broker_rate_limiter.decrement(user_guid, logger) | ||
end | ||
|
||
completion_percentage = i.to_f / NUM_REQUESTS_PER_USER * 100 | ||
if completion_percentage % 10 == 0 | ||
logger.info(" (#{completion_percentage.to_i}% completed)") | ||
end | ||
end | ||
end | ||
logger.info(' ... done.') | ||
|
||
num_rate_limit_events = 4 * NUM_USERS * NUM_REQUESTS_PER_USER | ||
logger.info('Results:') | ||
logger.info(" User CPU time = #{format("%.1f", result.utime)}s (per rate limit event: #{format("%.3f", result.utime / num_rate_limit_events * 1000)}ms)") | ||
logger.info(" System CPU time = #{format("%.1f", result.stime)}s (per rate limit event: #{format("%.3f", result.stime / num_rate_limit_events * 1000)}ms)") | ||
logger.info(" Total time = #{format("%.1f", result.total)}s (per rate limit event: #{format("%.3f", result.total / num_rate_limit_events * 1000)}ms)") | ||
logger.info(" Elapsed real time = #{format("%.1f", result.real)}s (per rate limit event: #{format("%.3f", result.real / num_rate_limit_events * 1000)}ms)") |