unicorn-instruments 0.0.1 → 0.0.2

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 (2) hide show
  1. data/unicorn-instruments.rb +41 -45
  2. metadata +1 -1
@@ -1,53 +1,49 @@
1
- module Unicorn::Instruments
2
- def self.instrument!
3
- Unicorn::HttpServer.class_eval do
4
- def worker_loop(worker)
5
- ppid = master_pid
6
- init_worker_process(worker)
7
- nr = 0 # this becomes negative if we need to reopen logs
8
- l = LISTENERS.dup
9
- ready = l.dup
1
+ class Unicorn::HttpServer
2
+ def worker_loop(worker)
3
+ ppid = master_pid
4
+ init_worker_process(worker)
5
+ nr = 0 # this becomes negative if we need to reopen logs
6
+ l = LISTENERS.dup
7
+ ready = l.dup
10
8
 
11
- # closing anything we IO.select on will raise EBADF
12
- trap(:USR1) { nr = -65536; SELF_PIPE[0].close rescue nil }
13
- trap(:QUIT) { worker = nil; LISTENERS.each { |s| s.close rescue nil }.clear }
14
- logger.info "worker=#{worker.nr} ready"
9
+ # closing anything we IO.select on will raise EBADF
10
+ trap(:USR1) { nr = -65536; SELF_PIPE[0].close rescue nil }
11
+ trap(:QUIT) { worker = nil; LISTENERS.each { |s| s.close rescue nil }.clear }
12
+ logger.info "worker=#{worker.nr} ready"
15
13
 
16
- begin
17
- nr < 0 and reopen_worker_logs(worker.nr)
18
- nr = 0
14
+ begin
15
+ nr < 0 and reopen_worker_logs(worker.nr)
16
+ nr = 0
17
+ worker.tick = Time.now.to_i
18
+ while sock = ready.shift
19
+ start_process = Time.now.to_i
20
+ if client = sock.kgio_tryaccept
21
+ process_client(client)
22
+ nr += 1
23
+ elapsed = (Time.now.to_i - start_process) * 1000
24
+ $stdout.puts("measure=unicorn.process val=#{elapsed}")
19
25
  worker.tick = Time.now.to_i
20
- while sock = ready.shift
21
- start_process = Time.now.to_i
22
- if client = sock.kgio_tryaccept
23
- process_client(client)
24
- nr += 1
25
- elapsed = (Time.now.to_i - start_process) * 1000
26
- $stdout.puts("measure=unicorn.process val=#{elapsed}")
27
- worker.tick = Time.now.to_i
28
- end
29
- break if nr < 0
30
- end
26
+ end
27
+ break if nr < 0
28
+ end
31
29
 
32
- # make the following bet: if we accepted clients this round,
33
- # we're probably reasonably busy, so avoid calling select()
34
- # and do a speculative non-blocking accept() on ready listeners
35
- # before we sleep again in select().
36
- unless nr == 0 # (nr < 0) => reopen logs (unlikely)
37
- ready = l.dup
38
- redo
39
- end
30
+ # make the following bet: if we accepted clients this round,
31
+ # we're probably reasonably busy, so avoid calling select()
32
+ # and do a speculative non-blocking accept() on ready listeners
33
+ # before we sleep again in select().
34
+ unless nr == 0 # (nr < 0) => reopen logs (unlikely)
35
+ ready = l.dup
36
+ redo
37
+ end
40
38
 
41
- ppid == Process.ppid or return
39
+ ppid == Process.ppid or return
42
40
 
43
- # timeout used so we can detect parent death:
44
- worker.tick = Time.now.to_i
45
- ret = IO.select(l, nil, SELF_PIPE, @timeout) and ready = ret[0]
46
- rescue => e
47
- redo if nr < 0 && (Errno::EBADF === e || IOError === e) # reopen logs
48
- Unicorn.log_error(@logger, "listen loop error", e) if worker
49
- end while worker
50
- end
51
- end
41
+ # timeout used so we can detect parent death:
42
+ worker.tick = Time.now.to_i
43
+ ret = IO.select(l, nil, SELF_PIPE, @timeout) and ready = ret[0]
44
+ rescue => e
45
+ redo if nr < 0 && (Errno::EBADF === e || IOError === e) # reopen logs
46
+ Unicorn.log_error(@logger, "listen loop error", e) if worker
47
+ end while worker
52
48
  end
53
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicorn-instruments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: