Skip to content

Commit

Permalink
still trying to see positive results from batch rest streaming... so …
Browse files Browse the repository at this point in the history
…far no luck
  • Loading branch information
maxdemarzi committed Jun 5, 2012
1 parent 2a2333c commit 8aa9f96
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 15 deletions.
19 changes: 8 additions & 11 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,16 @@ def batch(*args)
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json;stream=true'} }
options = { :body => batch.to_json,
:headers => {'Content-Type' => 'application/json'
# Seeing connection reset by peer errors
# and timeouts.
#, 'Accept' => 'application/json;stream=true'
},
:write_timeout => 600 }
post("/batch", options)
end

def batch_not_streaming(*args)
batch = []
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
post("/batch", options)
end


# For testing (use a separate neo4j instance)
# call this before each test or spec
def clean_database(sanity_check = "not_really")
Expand Down
99 changes: 95 additions & 4 deletions spec/integration/streaming_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,105 @@
end

it "can batch a bunch of nodes streaming" do
commands = 500.times.collect{|x| [:create_node, {:name => "node-#{x}"}]}
class Enumerator
def next_json
begin
self.next.to_json.to_s
rescue StopIteration
return ""
end
end
end
#Enumerator.class_eval{ alias :call :next}
Enumerator.class_eval{ alias :call :next_json}
#module Enumerable
# class Enumerator
# #alias :call :next
# class_eval{ alias :call :next}
# end
#end

module Neography
class Rest

def batch_streaming(*args)
batch = []
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end
options = { :body => batch.to_json,
:headers => {'Content-Type' => 'application/json',
# Seeing connection reset by peer errors
# and timeouts.
'Accept' => 'application/json;stream=true'
},
:write_timeout => 600 }
post("/batch", options)
end

def batch_not_streaming(*args)
batch = []
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
post("/batch", options)
end


def batch_chunked(*args)
batch = []
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end

file = StringIO.new(batch.to_json)
#file = Tempfile.new('a')
#file.write(batch.to_json)
#file.rewind
chunker = lambda do
file.read(50000).to_s
end

options = { :headers => {'Content-Type' => 'application/json',
'Accept' => 'application/json;stream=true'},
:request_block => chunker,
:write_timeout => 600
}
post("/batch", options)
end

def batch_chunked2(*args)
batch = []
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end

options = { :headers => {'Content-Type' => 'application/json'
},
:request_block => batch.each_slice(1000),
:write_timeout => 600
}
post("/batch", options)
end


end
end

commands = 2000.times.collect{|x| [:create_node, {:name => "node-#{x}"}]}
file = StringIO.new(commands.to_json)

Benchmark.bm do |x|
x.report("batch ") { @new_nodes = @neo.batch_not_streaming *commands }
x.report("streaming batch ") { @new_nodes_streaming = @neo.batch *commands }
x.report("batch ") { @new_nodes = @neo.batch *commands }
x.report("batch streaming ") { @new_nodes = @neo.batch_streaming *commands }
x.report("batch chunked ") { @new_nodes_streaming = @neo.batch_chunked *commands }
x.report("batch chunked 2 ") { @new_nodes_streaming = @neo.batch_chunked2 *commands }
x.report("batch not streaming ") { @new_nodes_not_streaming = @neo.batch_not_streaming *commands }
end
@new_nodes_not_streaming.should_not be_nil
@new_nodes.should_not be_nil
@new_nodes_streaming.should_not be_nil
pending
end

end

0 comments on commit 8aa9f96

Please sign in to comment.