Skip to content
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

Add helper script to benchmark rate limiting #3326

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions scripts/benchmark_rate_limiting.rb
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 = #{sprintf('%.1f', result.utime)}s (per rate limit event: #{sprintf('%.3f', result.utime / num_rate_limit_events * 1000)}ms)")
logger.info(" System CPU time = #{sprintf('%.1f', result.stime)}s (per rate limit event: #{sprintf('%.3f', result.stime / num_rate_limit_events * 1000)}ms)")
logger.info(" Total time = #{sprintf('%.1f', result.total)}s (per rate limit event: #{sprintf('%.3f', result.total / num_rate_limit_events * 1000)}ms)")
logger.info(" Elapsed real time = #{sprintf('%.1f', result.real)}s (per rate limit event: #{sprintf('%.3f', result.real / num_rate_limit_events * 1000)}ms)")