Skip to content

Instantly share code, notes, and snippets.

@warhammerkid
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warhammerkid/196a8c20509d3871f9a3 to your computer and use it in GitHub Desktop.
Save warhammerkid/196a8c20509d3871f9a3 to your computer and use it in GitHub Desktop.
Parsec Benchmark
require 'typhoeus'
require 'json'
RAID_GROUP_COUNT = 500
RAID_GROUP_PASSWORD = 'pass'
RAID_USER_COUNT = 8
HOST_NAME = 'parsec.chromedshark.com'
=begin
# Build raid groups
puts "Building raid groups..."
hydra = Typhoeus::Hydra.new
RAID_GROUP_COUNT.times do |gid|
group_name = "TestRaidGroup#{gid+1}"
group_request = {
:requestedName => group_name,
:requestedPassword => RAID_GROUP_PASSWORD,
:adminPassword => RAID_GROUP_PASSWORD
}
hydra.queue Typhoeus::Request.new("#{HOST_NAME}/api/RequestRaidGroup", method: :post, body: group_request.to_json, headers: {'Content-Type' => 'application/json'})
end
hydra.run
=end
# Build urls file
File.open('urls.txt', 'w') do |f|
RAID_GROUP_COUNT.times do |gid|
RAID_USER_COUNT.times do |uid|
bench_request = {
:RaidGroup => "TestRaidGroup#{gid+1}",
:RaidPassword => RAID_GROUP_PASSWORD,
:Statistics => {
:RaidUserId => uid+1,
:CharacterName => "Test Character",
:DamageOut => 2000,
:DamageIn => 100
}
}
request_string = bench_request.to_json
f.puts "http://parsec.chromedshark.com/api/SyncRaidStats POST #{request_string}"
end
end
end
# Hammer the server
exec "siege -b -c 600 -r 1000 -q -f urls.txt"
require 'net/http'
require 'typhoeus'
require 'json'
RAID_GROUP_COUNT = 500
RAID_GROUP_PASSWORD = 'pass'
RAID_USER_COUNT = 8
HOST_NAME = 'parsec.chromedshark.com'
=begin
# Build raid groups
http = Net::HTTP.new(*HOST_NAME.split(':'))
RAID_GROUP_COUNT.times do |gid|
resp = http.post2("/api/v2/raid_group?name=TestRaidGroup#{gid+1}&password=#{RAID_GROUP_PASSWORD}&adminPassword=#{RAID_GROUP_PASSWORD}", '')
raise "Failed: #{resp.body}" unless resp.code == '200'
end
=end
# Create user tokens
Typhoeus::Config.memoize = false
token_requests = []
hydra = Typhoeus::Hydra.new
RAID_GROUP_COUNT.times do |gid|
RAID_USER_COUNT.times do |uid|
request = Typhoeus::Request.new("#{HOST_NAME}/api/v2/connect?name=TestRaidGroup#{gid+1}&password=#{RAID_GROUP_PASSWORD}", method: :post, body: '', headers: {'Content-Type' => 'application/json'})
token_requests << request
hydra.queue request
end
end
hydra.run
# Build urls file
bench_request = {
:RaidUserId => 500,
:CharacterName => "Test Character",
:DamageOut => 2000,
:DamageIn => 100
}
request_string = bench_request.to_json
File.open('urls.txt', 'w') do |f|
token_requests.each do |request|
token = request.response.body
f.puts "http://#{HOST_NAME}/api/v2/stats?t=#{token} POST #{request_string}"
end
end
# Hammer the server
exec "siege -b -c 600 -r 1000 -q -f urls.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment