Last active
August 29, 2015 14:20
-
-
Save calonso/a26da8aa23f88e59abf4 to your computer and use it in GitHub Desktop.
Ruby program to profile an insert in Cassandra
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
#!/usr/bin/env bundle exec ruby | |
Bundler.setup | |
Bundler.require | |
require 'yaml' | |
def config | |
YAML.load_file File.expand_path('../../cassandra.yml', __FILE__) | |
end | |
success = false | |
result = RubyProf.profile do | |
cluster = Cassandra.cluster config | |
session = cluster.connect | |
session.execute "CREATE KEYSPACE carlos_profiling WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }" | |
session.execute "USE carlos_profiling" | |
session.execute "CREATE TABLE events ( | |
subscription_id varchar, | |
timestamp timestamp, | |
v1 float, | |
v2 float, | |
v3 varchar, | |
v4 int, | |
PRIMARY KEY (subscription_id, timestamp) | |
)" | |
session.execute " | |
INSERT INTO events (subscription_id, timestamp, v1, v2t, v3, v4) | |
VALUES ('12345-09876', '#{Time.now.to_i}', 33.3, 51.1, '8776655', 421) | |
", consistency: :one | |
session.execute "DROP KEYSPACE carlos_profiling" | |
success = true | |
end | |
raise 'Something failed inside the profiled block. Execute without profiling to see the exceptions!' unless success | |
printer = RubyProf::GraphPrinter.new(result) | |
printer.print(File.new("/tmp/profile-report.txt", 'w'), min_percent: 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment