Last active
January 31, 2016 23:04
-
-
Save pmashchak/bb2f898ea1c916eca40d to your computer and use it in GitHub Desktop.
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
module Client | |
TABLE = 'TestDevelopment1' | |
def client | |
Aws::DynamoDB::Client.new(region: 'No', | |
credentials: Rails.configuration.api.pulsar.creds, | |
endpoint: Rails.configuration.api.pulsar.east, | |
ssl_verify_peer: false) | |
end | |
def item(id) | |
client.get_item(table_name: TABLE, key: { 'id' => id }) | |
end | |
def create_table | |
client.create_table( | |
table_name: TABLE, | |
attribute_definitions: [ | |
{ attribute_name: 'id', attribute_type: 'S' }, | |
{ attribute_name: 'device_id', attribute_type: 'S' } ], | |
key_schema: [ { attribute_name: 'id', key_type: 'HASH' }, { attribute_name: 'device_id', key_type: 'RANGE'} ], | |
global_secondary_indexes: [ { | |
index_name: 'device_id', | |
key_schema: [{attribute_name: 'device_id', key_type: 'HASH'}], | |
projection: { projection_type: 'ALL' }, | |
provisioned_throughput: { read_capacity_units: 1, write_capacity_units: 1 } } ], | |
provisioned_throughput: { read_capacity_units: 1, write_capacity_units: 1 }) | |
end | |
def find(device_id) | |
client.query( | |
table_name: TABLE, | |
index_name: 'device_id', | |
key_condition_expression: 'device_id = :device', | |
expression_attribute_values: { ':device' => device_id }) | |
end | |
def item(device_id) | |
client.query(table_name: TABLE, index_name: 'device_id') | |
end | |
def delete_table | |
client.delete_table(table_name: TABLE) | |
end | |
def push_data | |
(1..5).each do |i| | |
client.put_item(table_name: TABLE, item: { id: i.to_s, device_id: rand(100).to_s, session: SecureRandom.hex } ) | |
end | |
end | |
def put(id, device_id) | |
client.put_item(table_name: TABLE, item: { id: id.to_s, device_id: device_id.to_s, session: SecureRandom.hex } ) | |
end | |
def all | |
client.scan(table_name: TABLE) | |
end | |
end | |
Benchmark.bm(7) do |x| | |
x.report("index ") do | |
10.times do | |
c.get_item(table_name: 'GamesAutoPair', key: {id: "2256690759166085184-2601:0088:8003:354F"}).item | |
end | |
end | |
x.report("second e") do | |
10.times do | |
c.query(table_name: 'GamesAutoPair', index_name: 'ip_GSI', | |
key_condition_expression: 'ip = :ip', | |
expression_attribute_values: { ':ip' => '2601:0088:8003:354F' }, | |
select: 'ALL_PROJECTED_ATTRIBUTES', scan_index_forward: 'False') | |
end | |
end | |
x.report("second k") do | |
10.times do | |
c.query(table_name: 'GamesAutoPair', index_name: 'ip_GSI', | |
key_conditions: { 'ip' => { attribute_value_list: ['2601:0088:8003:354F'], | |
comparison_operator: 'EQ' } }, | |
select: 'ALL_PROJECTED_ATTRIBUTES', scan_index_forward: 'False') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment