concur 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b75da71699ffaf065b8984ccae5b2ffc3da5b130
4
+ data.tar.gz: b3d7b9c60e085b239db6dfc9f7f7773c35ea2a48
5
+ SHA512:
6
+ metadata.gz: 6247b021a6acf3c3755c8cdffb3b77da20d5e39209e484809ec7b4b897802f297c7b464ccfe92f7e5fe3b6ce8d81a4a2c5dd9d9bee4f41d974f444a6c351daa6
7
+ data.tar.gz: 134f27a9c74b0d975c1fe215c363cba43bb17119e376fdd2e9ed9981f9944efff5df531de7f9b67b185ed42330b54210cabfd727a78749bb6039a800c208b632
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.idea
2
+ /pkg
3
+ *.sublime*
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require './lib/concur.rb'
2
+
3
+ begin
4
+ require 'jeweler2'
5
+ Jeweler::Tasks.new do |gemspec|
6
+ gemspec.name = "concur"
7
+ gemspec.summary = "A concurrency library for Ruby inspired by java.util.concurrency and Go (golang). By http://www.appoxy.com"
8
+ gemspec.email = "travis@appoxy.com"
9
+ gemspec.homepage = "http://github.com/treeder/concur/"
10
+ gemspec.description = "A concurrency library for Ruby inspired by java.util.concurrency and Go (golang). By http://www.appoxy.com"
11
+ gemspec.authors = ["Travis Reeder"]
12
+ gemspec.files = FileList['lib/**/*.rb']
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install jeweler2"
17
+ end
18
+
data/concur.gemspec ADDED
@@ -0,0 +1,25 @@
1
+
2
+ require File.expand_path('../lib/concur/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Travis Reeder"]
6
+ gem.email = ["treeder@gmail.com"]
7
+ gem.description = "A concurrency library for Ruby inspired by java.util.concurrency and Go (golang). By http://www.appoxy.com"
8
+ gem.summary = "A concurrency library for Ruby inspired by java.util.concurrency and Go (golang). By http://www.appoxy.com"
9
+ gem.homepage = "https://github.com/treeder/concur"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "concur"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Concur::VERSION
17
+
18
+ gem.required_rubygems_version = ">= 1.3.6"
19
+ gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
20
+
21
+ gem.add_runtime_dependency "concur"
22
+
23
+ gem.add_development_dependency "test-unit"
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Concur
2
+ VERSION = "2.1.0"
3
+ end
data/lib/future.rb CHANGED
@@ -34,12 +34,18 @@ module Concur
34
34
  @result = @callable.call(@channel)
35
35
  Concur.logger.debug 'callable result: ' + @result.inspect
36
36
  rescue Exception => ex
37
- Concur.logger.debug "Error occurred! #{ex.class.name}: #{ex.message}: " + ex.backtrace.inspect
37
+ Concur.logger.info "Error occurred! #{ex.class.name}: #{ex.message}: " + ex.backtrace.inspect
38
38
  @ex = ex
39
39
  end
40
+ if @channel
41
+ r = (@result || @ex)
42
+ puts "pusing #{r} to channel"
43
+ @channel << r
44
+ end
40
45
  @complete = true
41
46
  @cv.broadcast
42
47
 
48
+
43
49
  end
44
50
 
45
51
  def call(channel=nil)
data/test/job.rb ADDED
@@ -0,0 +1,51 @@
1
+ require_relative '../lib/runnable'
2
+ require 'rest'
3
+
4
+ class Job
5
+ include Concur::Runnable
6
+
7
+ def initialize(i, options={})
8
+ @i = i
9
+ if options[:em]
10
+ @em = true
11
+ end
12
+ @rest = Rest::Client.new
13
+ end
14
+
15
+ def em_request(url)
16
+ puts 'emrequest for ' + url
17
+ http = EventMachine::Protocols::HttpClient.request(
18
+ :host => url,
19
+ :port => 80,
20
+ :request => "/"
21
+ )
22
+ http.callback { |response|
23
+ puts response[:status]
24
+ puts response[:headers]
25
+ puts response[:content]
26
+ }
27
+ end
28
+
29
+ def run
30
+ puts "Starting #{@i}... em? #{@em}"
31
+ # sleep 1
32
+ urls = ["www.yahoo.com", "www.microsoft.com"] # , "www.github.com"
33
+ if @em
34
+ urls.each do |u|
35
+ em_request(u)
36
+ end
37
+ else
38
+ urls.each do |u|
39
+ get(u)
40
+ end
41
+ end
42
+ puts "Finished #{@i}"
43
+ "response #{@i}"
44
+ end
45
+
46
+ def get(url)
47
+ puts 'getting ' + url
48
+ @rest.get "http://#{url}"
49
+ end
50
+
51
+ end
@@ -0,0 +1,89 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+ require 'rest'
4
+ require_relative '../lib/concur'
5
+ require_relative 'job'
6
+
7
+
8
+ class TestConcur < Test::Unit::TestCase
9
+ @@durations = []
10
+
11
+ def test_speed_comparison
12
+ times = 10
13
+
14
+ # todo: use quicky gem
15
+
16
+ executor = Concur::Executor.new_single_threaded_executor
17
+ non_concurrent_duration = run_gets("non concurrent", executor)
18
+ executor.shutdown
19
+
20
+ executor = Concur::Executor.new_multi_threaded_executor
21
+ concurrent_duration = run_gets("multi thread", executor)
22
+ assert concurrent_duration < (non_concurrent_duration/2)
23
+ executor.shutdown
24
+
25
+ executor = Concur::Executor.new_thread_pool_executor(4)
26
+ pooled_duration = run_gets("thread pool", executor)
27
+ assert pooled_duration < (non_concurrent_duration/2)
28
+ executor.shutdown
29
+ #
30
+ #executor = Concur::Executor.new_eventmachine_executor()
31
+ #em_duration = run_gets("eventmachine", executor)
32
+ #assert em_duration < (non_concurrent_duration/2)
33
+ #executor.shutdown
34
+
35
+ puts "----"
36
+ @@durations.each do |s|
37
+ puts s
38
+ end
39
+
40
+ end
41
+
42
+ def run_gets(name, executor)
43
+ puts "Running #{name}..."
44
+ start_time = Time.now
45
+ rest = Rest::Client.new
46
+
47
+ futures = []
48
+ 10.times do |i|
49
+ url = "http://rest-test.iron.io/code/200"
50
+ futures << executor.execute() do
51
+ response = rest.get(url)
52
+ end
53
+ end
54
+ futures.each do |f|
55
+ puts 'f=' + f.inspect
56
+ # puts 'got=' + f.get.inspect
57
+ assert f.get.code >= 200 && f.get.code < 400
58
+ end
59
+ concurrent_duration = Time.now - start_time
60
+ o = "#{name} duration=" + concurrent_duration.to_s
61
+ puts o
62
+ @@durations << o
63
+ concurrent_duration
64
+ end
65
+
66
+ def run_jobs(name, executor, times, options={})
67
+ puts "Running #{name}..."
68
+ start_time = Time.now
69
+
70
+ jobs = []
71
+ times.times do |i|
72
+ job = Job.new(i, options)
73
+ jobs << executor.execute(job)
74
+ end
75
+ jobs.each do |j|
76
+ puts "result=#{j.get}"
77
+ end
78
+ concurrent_duration = Time.now - start_time
79
+ o = "#{name} duration=" + concurrent_duration.to_s
80
+ puts o
81
+ @@durations << o
82
+ concurrent_duration
83
+ end
84
+
85
+
86
+ end
87
+
88
+
89
+
data/test/tmp.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'thread'
2
+
3
+ @queue = Queue.new
4
+ 100.times do |i|
5
+ Thread.new do
6
+ @queue << "hi"
7
+ end
8
+ end
9
+
10
+ puts "waiting on channel..."
11
+ while (x = @queue.pop(true)) do
12
+ puts "Got #{x} from channel"
13
+ end
metadata CHANGED
@@ -1,29 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concur
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Travis Reeder
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concur
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
14
41
  description: A concurrency library for Ruby inspired by java.util.concurrency and
15
42
  Go (golang). By http://www.appoxy.com
16
- email: travis@appoxy.com
43
+ email:
44
+ - treeder@gmail.com
17
45
  executables: []
18
46
  extensions: []
19
- extra_rdoc_files:
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
20
50
  - LICENSE.markdown
21
51
  - README.md
22
- files:
52
+ - Rakefile
53
+ - concur.gemspec
23
54
  - lib/completer.rb
24
55
  - lib/concur.rb
25
56
  - lib/concur/config.rb
26
- - lib/concur/go.rb
57
+ - lib/concur/version.rb
27
58
  - lib/executor.rb
28
59
  - lib/executors/event_machine_executor.rb
29
60
  - lib/executors/never_block_executor.rb
@@ -31,31 +62,34 @@ files:
31
62
  - lib/futures/event_machine_future.rb
32
63
  - lib/runnable.rb
33
64
  - lib/thread_pool.rb
34
- - LICENSE.markdown
35
- - README.md
36
- homepage: http://github.com/treeder/concur/
65
+ - test/job.rb
66
+ - test/test_concur.rb
67
+ - test/tmp.rb
68
+ homepage: https://github.com/treeder/concur
37
69
  licenses: []
70
+ metadata: {}
38
71
  post_install_message:
39
72
  rdoc_options: []
40
73
  require_paths:
41
74
  - lib
42
75
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
76
  requirements:
45
- - - ! '>='
77
+ - - '>='
46
78
  - !ruby/object:Gem::Version
47
- version: '0'
79
+ version: '1.9'
48
80
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
81
  requirements:
51
- - - ! '>='
82
+ - - '>='
52
83
  - !ruby/object:Gem::Version
53
- version: '0'
84
+ version: 1.3.6
54
85
  requirements: []
55
86
  rubyforge_project:
56
- rubygems_version: 1.8.25
87
+ rubygems_version: 2.0.3
57
88
  signing_key:
58
- specification_version: 3
89
+ specification_version: 4
59
90
  summary: A concurrency library for Ruby inspired by java.util.concurrency and Go (golang).
60
91
  By http://www.appoxy.com
61
- test_files: []
92
+ test_files:
93
+ - test/job.rb
94
+ - test/test_concur.rb
95
+ - test/tmp.rb
data/lib/concur/go.rb DELETED
@@ -1,57 +0,0 @@
1
- module Kernel
2
- def go(ch=nil, &blk)
3
- future = Concur.gok.executor.execute(nil, ch, &blk)
4
- future
5
- end
6
- end
7
-
8
- module Concur
9
- class GoKernel
10
- def initialize(config)
11
- @config = config
12
- @executor = Concur::Executor.new_thread_pool_executor(@config.max_threads)
13
- @config.add_listener(@executor)
14
- end
15
-
16
- def executor
17
- @executor
18
- end
19
- end
20
-
21
- @gok = GoKernel.new(Concur.config)
22
-
23
- def self.gok
24
- @gok
25
- end
26
-
27
- class Channel
28
- def initialize
29
- @queue = Queue.new
30
- end
31
-
32
- def <<(ob)
33
- @queue << ob
34
- end
35
-
36
- def shift
37
- begin
38
- @queue.shift
39
- rescue Exception => ex
40
- #puts ex.class.name
41
- #p ex
42
- #p ex.message
43
- if ex.class.name == "fatal" && ex.message.include?("deadlock")
44
- return nil
45
- end
46
- raise ex
47
- end
48
- end
49
-
50
- def each(&blk)
51
- while (x = shift) do
52
- yield x
53
- end
54
- end
55
- end
56
- end
57
-