ppool 1.5.0 → 1.5.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/time_stats.rb +85 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f09e2d6b93728af6217c3215ba81e6b9c1b38417
4
- data.tar.gz: 8422bbc116f119e168191fc5dede318f8d339488
3
+ metadata.gz: 4c69ce399139048e9031d63877cd803874b57dc3
4
+ data.tar.gz: e610ebff443e30d963f02bc2a6d2c599227a7fe8
5
5
  SHA512:
6
- metadata.gz: cdb05df7fd35d02fe440ce91863bce35f7ebfc07331851bf2856302a0b96dbbe6eb1020c0cb31638c52bb2fa909e6077b5f44a5949d1ec7dcfeaafecd4ee70fe
7
- data.tar.gz: cf690c45a03b79b6aaf97b75b139c8ee8d7311a56c9616fd849f5bb81e8b6a6f81a171d2a9bf9475e487bd11e95c884c025deaa2d6223d2fe437898e82c0bf94
6
+ metadata.gz: 49abd8fe4955acd87d4644fec5d346c044ef929c7b30fbf6ebd021e88ee4f666ec69e7a562d9cb568d64011cd0ffb13148bfa9dee4654dc728e81d240cf6e476
7
+ data.tar.gz: 154fc963ad7dc9997fc72eac889c15fba6cfbe6397c28ae53365e5b5f4e930000ad8ea961f5f28422c7976deb23850e8ff81f1ae11a94764a21788819b877339
@@ -0,0 +1,85 @@
1
+ #
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2017 Paul Taylor
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #
24
+
25
+ module PPool
26
+
27
+ class TimeStats
28
+
29
+ def initialize(average_size)
30
+ @average_size = average_size
31
+ @start_time = {}
32
+ @process_count = 0
33
+ @elapsed_time = {}
34
+ @total_elapsed = 0
35
+ end
36
+
37
+
38
+ def process_started(pid)
39
+ @start_time[pid] = Time.now
40
+ end
41
+
42
+
43
+ def process_ended(pid)
44
+ elapsed_time = (Time.now - @start_time.delete(pid)) * 1000
45
+
46
+ if is_unlimited
47
+ @total_elapsed = @total_elapsed + elapsed_time
48
+ @process_count = @process_count + 1
49
+ else
50
+ i = @process_count % @average_size
51
+ @process_count = @process_count + 1
52
+ @elapsed_time[i] = elapsed_time
53
+ end
54
+ end
55
+
56
+
57
+ def average_elapsed_time()
58
+
59
+ if is_unlimited
60
+ if @process_count == 0
61
+ return 0
62
+ end
63
+ return (@total_elapsed / @process_count).round
64
+
65
+ else
66
+ size = @elapsed_time.size
67
+ if size == 0
68
+ return 0
69
+ end
70
+
71
+ total = @elapsed_time.inject(0) { |t, v|
72
+ t = t + v[1]
73
+ }
74
+
75
+ return (total / size).round
76
+ end
77
+ end
78
+
79
+
80
+ def is_unlimited
81
+ return @average_size == 0
82
+ end
83
+
84
+ end
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Taylor
@@ -82,6 +82,7 @@ files:
82
82
  - lib/process_pool_util.rb
83
83
  - lib/shell_process_controller.rb
84
84
  - lib/terminal_process_controller.rb
85
+ - lib/time_stats.rb
85
86
  - lib/timed_process_controller.rb
86
87
  homepage: http://rubygems.org/gems/ppool
87
88
  licenses: