windows_ionice 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +3 -0
  2. data/Rakefile +11 -0
  3. data/VERSION +1 -0
  4. data/bin/windows_ionice +74 -0
  5. metadata +87 -0
data/README ADDED
@@ -0,0 +1,3 @@
1
+ I want [need]/ to detect contention
2
+
3
+ Then either throw up more processes, or periodically allthread freeze the hog? (the command line param?)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'jeweler'
2
+ Jeweler::Tasks.new do |s|
3
+ s.name = "windows_ionice"
4
+ s.summary = "A command that helps windows run faster by punshing resource hogging processes (cpu/disk)"
5
+ s.email = "rogerdpack@gmail.com"
6
+ s.homepage = "http://github.com/rdp"
7
+ s.authors = ["Roger Pack"]
8
+ s.add_development_dependency 'rspec'
9
+ s.add_development_dependency 'sane'
10
+ s.add_dependency 'rdp-ruby-wmi'
11
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,74 @@
1
+ require 'rubygems' if $0 == __FILE__ && RUBY_VERSION < '1.9'
2
+ require 'sane'
3
+ require 'ruby-wmi'
4
+ require 'benchmark'
5
+
6
+ puts 'starting watcher...'
7
+
8
+ # take a snapshot of the processes' status
9
+ # could be more efficient by selecting just what we wanted, I suppose
10
+ def fill into_this
11
+ all = WMI::Win32_PerfRawData_PerfProc_Process.find(:all).each{|proc|
12
+ into_this[proc.IDProcess] = {:processor => proc.PercentProcessorTime.to_i, :data => proc.IODataBytesPerSec.to_i}
13
+ }
14
+ return all[0].TimeStamp_Sys100NS.to_i # these are all the same
15
+ end
16
+
17
+ #
18
+ # compare two snapshots
19
+ #
20
+ def diff_values first, second, time_diff, what_to_calculate
21
+ answer = {}
22
+ for key in first.keys
23
+ if first[key] != second[key] # sometimes they stay the same
24
+ begin
25
+ answer[key] = (first[key][what_to_calculate] - second[key][what_to_calculate]).to_f/time_diff
26
+ if what_to_calculate == :data
27
+ answer[key] *= 10_000_000 # strip off the 100_ns aspect
28
+ else
29
+ answer[key] *= 100 # percentages come as 0.99 -- we want 99 to mean 99% of one core
30
+ end
31
+
32
+ rescue
33
+ # sometimes the values are nil
34
+ # ignore I suppose
35
+ end
36
+ end
37
+ end
38
+ answer
39
+ end
40
+
41
+ loop {
42
+ print '.' if $VERBOSE
43
+ STDOUT.flush
44
+ old = {}
45
+
46
+ ts1 = fill old
47
+ $VERBOSE ? sleep( 1 ) : sleep( 3 )
48
+ new = {}
49
+ ts2 = fill new
50
+
51
+ for value in [:processor, :data]
52
+ sorted = diff_values( new, old, ts2 - ts1, value ) # give use "just data" or not
53
+ puts value, sorted.inspect if $VERBOSE
54
+ violated = []
55
+
56
+ sorted.each{|pid, reading|
57
+
58
+ if value == :processor
59
+ max = 97 # > 97% of one core -> penalt!
60
+ elsif value == :data
61
+ max = 1_000_000 # more than 1 MB/s -> penalt!
62
+ end
63
+
64
+ if reading > max && pid != 0 # using a full core (100) or more...
65
+ violated << pid
66
+ proc = WMI::Win32_Process.find(:first, :conditions => {:ProcessId => pid.to_i})
67
+ if proc.Priority > 4 # appears that 7 or 8 here mean normal prio...
68
+ proc.SetPriority 64 # set it to low priority
69
+ sputs "pid violated!", pid, value, reading, "was greater than", max, "punishing it"
70
+ end
71
+ end
72
+ }
73
+ end
74
+ }
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: windows_ionice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Roger Pack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-05 00:00:00 -07:00
13
+ default_executable: windows_ionice
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sane
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rdp-ruby-wmi
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description:
46
+ email: rogerdpack@gmail.com
47
+ executables:
48
+ - windows_ionice
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README
53
+ files:
54
+ - README
55
+ - Rakefile
56
+ - VERSION
57
+ - bin/windows_ionice
58
+ has_rdoc: true
59
+ homepage: http://github.com/rdp
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A command that helps windows run faster by punshing resource hogging processes (cpu/disk)
86
+ test_files: []
87
+