unicorn-instruments 0.0.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.
- data/unicorn-instruments.rb +53 -0
- metadata +62 -0
@@ -0,0 +1,53 @@
|
|
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
|
10
|
+
|
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"
|
15
|
+
|
16
|
+
begin
|
17
|
+
nr < 0 and reopen_worker_logs(worker.nr)
|
18
|
+
nr = 0
|
19
|
+
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
|
31
|
+
|
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
|
40
|
+
|
41
|
+
ppid == Process.ppid or return
|
42
|
+
|
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
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unicorn-instruments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Smith (♠ ace hacker)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: unicorn
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.6.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.6.2
|
30
|
+
description: Prints ruby processing time to stdout.
|
31
|
+
email: ryan@heroku.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- unicorn-instruments.rb
|
37
|
+
homepage: http://github.com/ryandotsmith/unicorn-instruments
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- .
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.23
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Monkey patch to unicorn to instruments methods.
|
62
|
+
test_files: []
|