Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby program to profile an insert in Cassandra
#!/usr/bin/env bundle exec ruby
require 'yaml'
def config
YAML.load_file File.expand_path('../../cassandra.yml', __FILE__)
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', '#{}', 33.3, 51.1, '8776655', 421)
", consistency: :one
session.execute "DROP KEYSPACE carlos_profiling"
success = true
raise 'Something failed inside the profiled block. Execute without profiling to see the exceptions!' unless success
printer =
printer.print("/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
You can’t perform that action at this time.