Permalink
Browse files

+ is_parallel

  • Loading branch information...
1 parent d853fdc commit 6c34f50f42154f27b66ecb175ce7c7b441aacd27 Andrew Zinenko committed Sep 22, 2012
Showing with 85 additions and 92 deletions.
  1. +1 −1 .document
  2. +1 −1 .rvmrc
  3. +24 −0 Gemfile.lock
  4. +3 −3 README.md
  5. +8 −8 Rakefile
  6. +7 −1 lib/vk-ruby/core.rb
  7. +35 −26 tests/benchmarks.rb
  8. +0 −52 tests/configurable.rb
  9. +6 −0 vk-ruby.gemspec
View
@@ -1,5 +1,5 @@
lib/**/*.rb
bin/*
--
+-
features/**/*.feature
LICENSE.txt
View
2 .rvmrc
@@ -1 +1 @@
-rvm use 1.9.2@vk-ruby --create
+rvm use ruby-1.9.3-p194@vk-ruby --create
View
@@ -13,19 +13,38 @@ GEM
remote: http://rubygems.org/
specs:
addressable (2.2.8)
+ cookiejar (0.3.0)
crack (0.3.1)
+ em-http-request (1.0.3)
+ addressable (>= 2.2.3)
+ cookiejar
+ em-socksify
+ eventmachine (>= 1.0.0.beta.4)
+ http_parser.rb (>= 0.5.3)
+ em-socksify (0.2.1)
+ eventmachine (>= 1.0.0.beta.4)
+ em-synchrony (1.0.2)
+ eventmachine (>= 1.0.0.beta.1)
+ eventmachine (1.0.0)
faraday (0.8.1)
multipart-post (~> 1.1)
faraday_middleware (0.8.8)
faraday (>= 0.7.4, < 0.9)
+ ffi (1.1.5)
+ http_parser.rb (0.5.3)
json_pure (1.7.4)
+ mime-types (1.19)
minitest (2.12.1)
multi_json (1.3.6)
multi_xml (0.5.1)
multipart-post (1.1.5)
oj (1.0.6)
+ patron (0.4.18)
rake (0.9.2.2)
transformer (0.2.2)
+ typhoeus (0.4.2)
+ ffi (~> 1.0)
+ mime-types (~> 1.18)
unicode_utils (1.3.0)
webmock (1.8.7)
addressable (>= 2.2.7)
@@ -36,10 +55,15 @@ PLATFORMS
ruby
DEPENDENCIES
+ em-http-request (~> 1.0.3)
+ em-synchrony (~> 1.0.2)
+ eventmachine (~> 1.0.0)
json_pure (~> 1.7.4)
minitest (~> 2.8)
oj (~> 1.0.6)
+ patron (~> 0.4.18)
rake (~> 0.9)
+ typhoeus (~> 0.4.2)
vk-ruby!
webmock (~> 1.0)
yajl-ruby (~> 1.1.0)
View
@@ -1,4 +1,4 @@
-#VK-RUBY
+#VK-RUBY
[![Build Status](https://secure.travis-ci.org/zinenko/vk-ruby.png)](http://travis-ci.org/zinenko/vk-ruby)
Ruby wrapper for vk.com API.
@@ -23,7 +23,7 @@ app.audio.search(q: 'Sting').map{|track| puts track.inspect} if app.authorize C
```
## Contributing to vk-ruby
-
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
@@ -34,4 +34,4 @@ app.audio.search(q: 'Sting').map{|track| puts track.inspect} if app.authorize C
## Copyright
-Copyright (c) 2011 Andrew Zinenko. See LICENSE.txt for further details.
+Copyright (c) 2011-2012 Andrew Zinenko. See LICENSE.txt for further details.
View
@@ -3,20 +3,20 @@
require 'rubygems'
require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
+# begin
+# Bundler.setup(:default, :development)
+# rescue Bundler::BundlerError => e
+# $stderr.puts e.message
+# $stderr.puts "Run `bundle install` to install missing gems"
+# exit e.status_code
+# end
require 'rake'
require 'rake/testtask'
task default: :test
Rake::TestTask.new do |test|
- test.pattern = 'tests/*_test.rb'
+ test.pattern = 'tests/benchmarks.rb'
test.verbose = true
end
View
@@ -39,6 +39,12 @@ def vk_call(method_name, params)
response.body['response']
end
+ def in_parallel(manager = nil, &block)
+ Faraday.new(parallel_manager: manager) do
+ yield if block_given?
+ end
+ end
+
def faraday_middleware
@faraday_middleware || proc do |faraday|
faraday.request :multipart
@@ -48,7 +54,7 @@ def faraday_middleware
faraday.response :xml, content_type: /\bxml$/
faraday.response :normalize_utf
faraday.response :validate_utf
- faraday.response :vk_logger, self.logger
+ # faraday.response :vk_logger, self.logger
faraday.adapter self.adapter
end
View
@@ -1,7 +1,11 @@
+require 'rubygems'
require 'minitest/autorun'
require 'minitest/benchmark'
require "vk-ruby"
require 'yaml'
+require 'rubygems'
+require 'em-synchrony'
+require 'em-synchrony/em-http'
if File.exists?("#{Dir.pwd}/config.yml")
YAML.load_file("#{Dir.pwd}/config.yml").each do |name, value|
@@ -12,57 +16,62 @@
class TestBench < MiniTest::Unit::TestCase
def self.bench_range
- [100, 10000]
+ [1000]
end
def setup
@vk = VK::Standalone.new app_id: APP_ID, access_token: ACCESS_TOKEN, logger: false
@fields = %w[uid first_name last_name nickname screen_name bdate sex city country photo_big has_mobile contacts education rate relation counters]
end
- # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
+ def per_request
+ 500
+ end
- [ :net_http, :em_http, :em_synchrony, :net_http_persistent, :patron ].each do |http_adapter|
- [:json_gem, :json_pure, :oj, :yajl].each do |json_engine|
+ def part_size
+ 10
+ end
- define_method "bench_#{http_adapter}_#{json_engine}" do
- @vk.adapter = http_adapter
- MultiJson.engine = json_engine
+ [ :net_http, :em_http, :em_synchrony, :net_http_persistent, :patron, :typhoeus ].each do |http_adapter|
+ [:json_gem, :json_pure, :oj, :yajl].each do |json_engine|
- assert_performance_linear 0.998 do |n| # n is a range value
- (1..n).each_slice(500) do |part|
- @vk.users.get(uids: part.join(','), fields: @fields)
- end
- end
+ define_method "bench_#{http_adapter}_#{json_engine}" do
+ @vk.adapter = http_adapter
+ MultiJson.engine = json_engine
- end
+ assert_performance_linear 0.998 do |n| # n is a range value
+ (1..n).each_slice( per_request ) do |part|
+ @vk.users.get(uids: part.join(','), fields: @fields)
+ end
+ end
- end
- end
+ end
- [ :em_http, :em_synchrony, :patron ].each do |http_adapter|
+ end
+ end
+
+ [ :em_http, :em_synchrony, :patron, :typhoeus ].each do |http_adapter|
[:json_gem, :json_pure, :oj, :yajl].each do |json_engine|
- define_method "bench_#{http_adapter}_#{json_engine}" do
+ define_method "bench_#{http_adapter}_#{json_engine}_parallel" do
@vk.adapter = http_adapter
MultiJson.engine = json_engine
- assert_performance_linear 0.998 do |n| # n is a range value
+ results = []
- (1..n).each_slice(5000) do |part|
+ assert_performance_linear 0.998 do |n|
+ (1..n).each_slice( per_request * part_size ) do |part|
+ @vk.in_parallel do |r|
- results = @vk.in_parallel([]) do |vk, r|
- part.each_slice(50) do |sub_part|
- r << @vk.users.get(uids: sub_part.join(','), fields: @fields)
+ part.each_slice( per_request ) do |sub_part|
+ results << @vk.users.get(uids: sub_part.join(','), fields: @fields)
end
- end
- puts results.inspect
+ end
end
-
end
- end
+ end
end
end
View
@@ -1,52 +0,0 @@
-require File.expand_path('../helpers', __FILE__)
-
-module Test
- A = 'A'
- B = 'B'
- D = 'D'
-
- class Application
- extend VK::Configurable
-
- C = 'C'
-
- attr_configurable :a, :b
- attr_configurable :c, :d, default: :default_value
-
- def initialize(params={})
- params.each{|key, value| send("#{key}=", value) }
- end
- end
-end
-
-class TestConfigurable < MiniTest::Unit::TestCase
-
- def setup
- @application = Test::Application.new(a: 1, d: 2)
- end
-
- def test_a
- assert_equal @application.a, 1
- @application.a = :new_value
- assert_equal @application.a, :new_value
- end
-
- def test_b
- assert_equal @application.b, 'B'
- @application.b = :new_value
- assert_equal @application.b, :new_value
- end
-
- def test_c
- assert_equal @application.c, :default_value
- @application.c = :new_value
- assert_equal @application.c, :new_value
- end
-
- def test_d
- assert_equal @application.d, 2
- @application.d = :new_value
- assert_equal @application.d, :new_value
- end
-
-end
View
@@ -30,6 +30,12 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'oj', '~> 1.0.6' unless RUBY_PLATFORM == 'java'
gem.add_development_dependency 'yajl-ruby', '~> 1.1.0' unless RUBY_PLATFORM == 'java'
gem.add_development_dependency 'json_pure', '~> 1.7.4'
+ gem.add_development_dependency 'eventmachine', '~> 1.0.0'
+ gem.add_development_dependency 'em-synchrony', '~> 1.0.2'
+ gem.add_development_dependency 'em-http-request', '~> 1.0.3'
+ gem.add_development_dependency 'patron', '~> 0.4.18'
+ gem.add_development_dependency 'typhoeus', '~> 0.4.2'
+ gem.add_development_dependency ' net-http-persistent', '2.7'
gem.require_paths = ['lib']
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')

0 comments on commit 6c34f50

Please sign in to comment.