Skip to content

Instantly share code, notes, and snippets.

@efi
Last active December 13, 2015 23:49
Show Gist options
  • Save efi/4994045 to your computer and use it in GitHub Desktop.
Save efi/4994045 to your computer and use it in GitHub Desktop.
# -*- encoding : utf-8 -*-
require 'rubygems'
require 'pacer'
Dir["titan-0.2.0/lib/\*.jar"].each { |jar| require jar }
# Benchmark code
def time ; start = Time.now ; yield ; puts "Executed in #{Time.now - start}" ; end
# Purge local Titan store and create new instance
system "rm /disk/tmp/titan/*"
titan_g = Java::ComThinkaureliusTitanCore::TitanFactory.open "/disk/tmp/titan"
# Wrap pacer around the titan graph
module Pacer ; class << self
def titan g
path = "/disk/tml/titan"
open = proc{ Pacer.open_graphs[path] || Pacer.open_graphs[path] = g }
shutdown = proc{ |g| g.blueprints_graph.shutdown ; Pacer.open_graphs.delete path }
PacerGraph.new(Pacer::SimpleEncoder, open, shutdown)
end
end ; end
pacer_g = Pacer.titan titan_g
# All kinds of indexing efforts - any single one of them suffices
titan_g.make_type.name("name").functional.indexed.data_type(Java::JavaLang::String.java_class).make_property_key
titan_g.createKeyIndex("name", Java::ComTinkerpopBlueprints::Vertex.java_class);
pacer_g.create_key_index(:name, :vertex)
# Create a simple small graph to show performance hit of non-indexing
pacer_g.transaction{(0..1500).each{|i| pacer_g.create_vertex nil, :name => "node#{i}"}}
time{ titan_g.get_vertices("name","node1337").count.to_s } # "Executed in 0.006" - fast
time{ pacer_g.v("name"=>"node666").count.to_s } # "Executed in 0.47" - slow!!!
p pacer_g.v(:name=>"node10").description # should show V-Index but does not...
p pacer_g.v(:noname=>"nope").description # should always show V-Property and does.
p pacer_g.key_indices # issues #<Set: {"name"}> - so the key_index is known!
pacer_g.shutdown
# -*- encoding : utf-8 -*-
require 'rubygems'
require 'pacer'
Dir["titan-0.2.0/lib/\*.jar"].each { |jar| require jar }
# Benchmark code
def time ; start = Time.now ; yield ; puts "Executed in #{Time.now - start}" ; end
# Purge local Titan store and create new instance
system "rm /disk/tmp/titan/*"
titan_g = Java::ComThinkaureliusTitanCore::TitanFactory.open "/disk/tmp/titan"
# Wrap pacer around the titan graph
module Pacer ; class << self
def titan g
path = "/disk/tml/titan"
open = proc{ Pacer.open_graphs[path] || Pacer.open_graphs[path] = g }
shutdown = proc{ |g| g.blueprints_graph.shutdown ; Pacer.open_graphs.delete path }
PacerGraph.new(Pacer::SimpleEncoder, open, shutdown)
end
end ; end
pacer_g = Pacer.titan titan_g
# All kinds of indexing efforts - any single one of them suffices
titan_g.make_type.name("name").functional.indexed.data_type(Java::JavaLang::String.java_class).make_property_key
titan_g.createKeyIndex("name", Java::ComTinkerpopBlueprints::Vertex.java_class);
pacer_g.create_key_index(:name, :vertex)
# Ugly patching (have pacer_g.features return true and pacer_g.indices return key_indices)
class FeatureProxy
def initialize original_features ; @features = original_features end
def supportsIndices ; true ; end
def method_missing(name, *args, &block) ; @features.public_send(name, *args, &block) end
end
def pacer_g.features ; FeatureProxy.new(blueprints_graph.features) ; end
def pacer_g.indices ; key_indices ; end
# Create a simple small graph to show performance hit of non-indexing
pacer_g.transaction{(0..1500).each{|i| pacer_g.create_vertex nil, :name => "node#{i}"}}
time{ titan_g.get_vertices("name","node1337").count.to_s } # "Executed in 0.006" - fast
time{ pacer_g.v("name"=>"node666").count.to_s } # "Executed in 0.017" - fast only with patch
p pacer_g.v(:name=>"node10").description # shows V-Index only with patch
p pacer_g.v(:noname=>"nope").description # should always show V-Property and does.
p pacer_g.key_indices # issues #<Set: {"name"}> - so the key_index is known!
pacer_g.shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment