Sha256: fdeaa8dd25ebc1ca267f2d65864dbe4d4e7c3ce878e06ce5d80ae44b48fd27cc

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
require File.expand_path('../lib/dm-adapter-simpledb', File.dirname(__FILE__))
require 'logger'

include DataMapper

class Post
  include Resource
  
  property :title, String, :key => true
  property :body,  Text
end

logger = ::Logger.new($stderr, ::Logger::DEBUG)

DataMapper.setup(
  :default,
  :domain        => "dm_simpledb_adapter_benchmark",
  :adapter       => 'simpledb',
  :create_domain => true,
  :logger        => logger,
  :batch_limit   => 10)

logger.info "Writing records"
100.times do |i|
  Post.create(:title => "title#{i}", :body => "body#{i}")
end

logger.info "Waiting a bit for consistency"
sleep 2

SDBTools::Transaction.on_close = 
  SDBTools::Transaction.log_transaction_close(logger)
SDBTools::Transaction.open("benchmark limited query") do |t|
  # With a batch limit of 10, this should result in two queries of LIMIT 10 and
  # one with LIMIT 5
  query      = Post.all(:limit => 25)
  item_count = query.to_a.size
  logger.info "Found #{item_count} items"
end

SDBTools::Transaction.on_close = 
  SDBTools::Transaction.log_transaction_close(logger)
SDBTools::Transaction.open("benchmark query with limit and offset") do |t|
  # With a batch limit of 10, this should result in two queries of LIMIT 10 and
  # one with LIMIT 5
  query      = Post.all(:limit => 25, :order => :title.asc, :offset => 25)
  item_count = query.to_a.size
  logger.info "Found #{item_count} items"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-adapter-simpledb-1.5.0 scripts/limits_benchmark
dm-adapter-simpledb-1.4.0 scripts/limits_benchmark