Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class WTF
- # CREATE KEYSPACE foo
- # WITH replication = {
- # 'class': 'SimpleStrategy',
- # 'replication_factor': 1
- # };
- #
- # USE foo;
- #
- # CREATE TABLE bar1 (
- # some_id bigint,
- # some_type text,
- # some_value int,
- # some_data text,
- # PRIMARY KEY((some_id, some_type), some_value)
- # );
- #
- # CREATE TABLE bar2 (
- # some_id bigint,
- # some_type text,
- # some_value_and_data text,
- # PRIMARY KEY((some_id, some_type))
- # );
- def initialize()
- # Connect to localhost by default
- @conn = Historian::ConnectionWrapper.new({})
- @conn.use('foo')
- @value = 0
- @id = rand(1000000)
- end
- def random_data
- (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
- end
- def random_id
- rand(25000000)
- end
- def insert1
- "INSERT INTO bar1(some_id,some_type,some_value,some_data) VALUES (#{@id},'blah',#{random_id},'#{random_data}');"
- end
- def insert2
- "INSERT INTO bar2(some_id,some_type,some_value_and_data) VALUES (#{@id},'blah','#{'%09d' % random_id}_#{random_data}');"
- end
- def many1
- 10000.times.map {|_| insert1 }
- end
- def many2
- 10000.times.map {|_| insert2 }
- end
- def execute_separetely(cmds)
- t1 = Time.now
- cmds.each { |cmd| @conn.execute(cmd, :one) }
- puts "Separetely: #{Time.now-t1}"
- end
- def execute_batch(cmds)
- cmd = "BEGIN BATCH\n"
- cmd << cmds.join("\n")
- cmd << "APPLY BATCH;\n"
- t1 = Time.now
- @conn.execute(cmd, :one)
- puts "Batch: #{Time.now-t1}"
- end
- def showoff
- puts "Using composite keys"
- execute_separetely many1
- execute_batch many1
- puts "Using just partition key and wide row"
- execute_separetely many2
- execute_batch many2
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement