-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifications and performance improvements (#200)
* Add pool_concurrency_test manual spec Add MT connection count without Mutex * Drop checkout_some, simpler pool_prepared statement * Make pool statement a struct * Drop StringKeyCache mutex The StringKeyCache is now only used inside a connection. It's assumed that connections are not used concurrently with multiple queries. * Drop do_close in pool statements * Add specs and update comment * Fix typo
- Loading branch information
Showing
10 changed files
with
139 additions
and
149 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
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
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,68 @@ | ||
# This file is to be executed as: | ||
# | ||
# % crystal run --release [-Dpreview_mt] ./spec/manual/pool_concurrency_test.cr -- --options="max_pool_size=5" --duration=30 --concurrency=4 | ||
# | ||
# | ||
|
||
require "option_parser" | ||
require "../dummy_driver" | ||
require "../../src/db" | ||
|
||
options = "" | ||
duration = 3 | ||
concurrency = 4 | ||
|
||
OptionParser.parse do |parser| | ||
parser.banner = "Usage: pool_concurrency_test [arguments]" | ||
parser.on("-o", "--options=VALUE", "Connection string options") { |v| options = v } | ||
parser.on("-d", "--duration=SECONDS", "Specifies the duration in seconds") { |v| duration = v.to_i } | ||
parser.on("-c", "--concurrency=VALUE", "Specifies the concurrent requests to perform") { |v| concurrency = v.to_i } | ||
parser.on("-h", "--help", "Show this help") do | ||
puts parser | ||
exit | ||
end | ||
parser.invalid_option do |flag| | ||
STDERR.puts "ERROR: #{flag} is not a valid option." | ||
STDERR.puts parser | ||
exit(1) | ||
end | ||
end | ||
|
||
multi_threaded = {% if flag?(:preview_mt) %} ENV["CRYSTAL_WORKERS"]?.try(&.to_i?) || 4 {% else %} false {% end %} | ||
release = {% if flag?(:release) %} true {% else %} false {% end %} | ||
|
||
if !release | ||
puts "WARNING: This should be run in release mode." | ||
end | ||
|
||
db = DB.open "dummy://host?#{options}" | ||
|
||
start_time = Time.monotonic | ||
|
||
puts "Starting test for #{duration} seconds..." | ||
|
||
concurrency.times do | ||
spawn do | ||
loop do | ||
db.scalar "1" | ||
Fiber.yield | ||
end | ||
end | ||
end | ||
|
||
sleep duration.seconds | ||
|
||
end_time = Time.monotonic | ||
|
||
puts " Options : #{options}" | ||
puts " Duration (sec) : #{duration} (actual #{end_time - start_time})" | ||
puts " Concurrency : #{concurrency}" | ||
puts " Multi Threaded : #{multi_threaded ? "Yes (#{multi_threaded})" : "No"}" | ||
puts "Total Connections : #{DummyDriver::DummyConnection.connections_count}" | ||
puts " Total Statements : #{DummyDriver::DummyStatement.statements_count}" | ||
puts " Total Queries : #{DummyDriver::DummyStatement.statements_exec_count}" | ||
puts " Throughput (q/s) : #{DummyDriver::DummyStatement.statements_exec_count / duration}" | ||
|
||
if !release | ||
puts "WARNING: This should be run in release mode." | ||
end |
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
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
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
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
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
Oops, something went wrong.