-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5712f6f
commit 89b5d3d
Showing
3 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,151 @@ | ||
require 'bundler/inline' | ||
gemfile do | ||
source 'https://rubygems.org' | ||
gem 'benchmark-ips' | ||
gem 'sorted_set' | ||
gem 'cassandra-driver', require: 'cassandra' | ||
gem 'ilios' | ||
end | ||
|
||
|
||
Ilios::Cassandra.config = { | ||
keyspace: 'ilios', | ||
hosts: ['127.0.0.1'], | ||
} | ||
|
||
# Create table | ||
statement = Ilios::Cassandra.session.prepare(<<~CQL) | ||
CREATE TABLE IF NOT EXISTS ilios.benchmark ( | ||
id bigint, | ||
message text, | ||
created_at timestamp, | ||
PRIMARY KEY (id) | ||
) WITH compaction = { 'class' : 'LeveledCompactionStrategy' } | ||
AND gc_grace_seconds = 691200; | ||
CQL | ||
Ilios::Cassandra.session.execute(statement) | ||
|
||
|
||
class BenchmarkCassandra | ||
def initialize | ||
@cluster = Cassandra.cluster | ||
@keyspace = 'ilios' | ||
@session = @cluster.connect(@keyspace) | ||
end | ||
|
||
def run_execute(x) | ||
x.report('cassandra-driver:execute') do | ||
@session.execute(statement, { | ||
arguments: { | ||
id: Random.rand(2**40), | ||
message: 'hello', | ||
created_at: Time.now | ||
} | ||
}) | ||
end | ||
end | ||
|
||
def run_execute_async(x) | ||
x.report('cassandra-driver:execute_async') do | ||
future = @session.execute_async(statement, { | ||
arguments: { | ||
id: Random.rand(2**40), | ||
message: 'hello', | ||
created_at: Time.now | ||
} | ||
}) | ||
future.on_success do |rows| | ||
end | ||
end | ||
end | ||
|
||
def statement | ||
@statement ||= @session.prepare(<<~CQL) | ||
INSERT INTO ilios.benchmark ( | ||
id, | ||
message, | ||
created_at | ||
) VALUES (?, ?, ?) | ||
CQL | ||
end | ||
end | ||
|
||
class BenchmarkIlios | ||
def run_execute(x) | ||
x.report('ilios:execute') do | ||
statement.bind({ | ||
id: Random.rand(2**40), | ||
message: 'hello', | ||
created_at: Time.now | ||
}) | ||
Ilios::Cassandra.session.execute(statement) | ||
end | ||
end | ||
|
||
def run_execute_async(x) | ||
x.report('ilios:execute_async') do | ||
statement.bind({ | ||
id: Random.rand(2**40), | ||
message: 'hello', | ||
created_at: Time.now | ||
}) | ||
future = Ilios::Cassandra.session.execute_async(statement) | ||
future.on_success do |results| | ||
results.each do |row| | ||
end | ||
end | ||
end | ||
end | ||
|
||
def statement | ||
@statement ||= Ilios::Cassandra.session.prepare(<<-CQL) | ||
INSERT INTO ilios.benchmark ( | ||
id, | ||
message, | ||
created_at | ||
) VALUES (?, ?, ?) | ||
CQL | ||
end | ||
end | ||
|
||
puts "[ips]" | ||
Benchmark.ips do |x| | ||
BenchmarkCassandra.new.run_execute(x) | ||
BenchmarkCassandra.new.run_execute_async(x) | ||
end | ||
|
||
sleep 3 | ||
|
||
puts "" | ||
Benchmark.ips do |x| | ||
BenchmarkIlios.new.run_execute(x) | ||
BenchmarkIlios.new.run_execute_async(x) | ||
end | ||
|
||
=begin | ||
## Environment | ||
- OS: Manjaro Linux x86_64 | ||
- CPU: AMD Ryzen 9 7940HS | ||
- Compiler: gcc 13.2.1 | ||
## Results | ||
[ips] | ||
Warming up -------------------------------------- | ||
cassandra-driver:execute | ||
396.000 i/100ms | ||
cassandra-driver:execute_async | ||
3.506k i/100ms | ||
Calculating ------------------------------------- | ||
cassandra-driver:execute | ||
3.142k (±32.8%) i/s - 9.900k in 5.092600s | ||
cassandra-driver:execute_async | ||
36.423k (±27.0%) i/s - 157.770k in 5.003134s | ||
Warming up -------------------------------------- | ||
ilios:execute 292.000 i/100ms | ||
ilios:execute_async 315.000 i/100ms | ||
Calculating ------------------------------------- | ||
ilios:execute 4.540k (± 4.8%) i/s - 22.776k in 5.030420s | ||
ilios:execute_async 167.021k (±27.0%) i/s - 770.175k in 4.994409s | ||
=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