-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.stats.html
211 lines (174 loc) · 8.73 KB
/
file.stats.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
<meta name='apple-touch-fullscreen' content='yes'>
<meta name='apple-mobile-web-app-capable' content='yes'>
<meta name='apple-mobile-web-app-status-bar-style' content='rgba(228,228,228,1.0)'>
<title>File: Stats — Puma master</title>
<link rel='stylesheet' type='text/css' href='../css/y_fonts.css' />
<link rel='stylesheet' type='text/css' href='../css/highlight.github.css' />
<link rel='stylesheet' type='text/css' href='../css/y_style.css' />
<link rel='stylesheet' type='text/css' href='../css/y_list.css' />
<link rel='stylesheet' type='text/css' href='../css/y_color.css' />
<script type='text/javascript'>
var pathId = "stats",
relpath = '';
var t2Info = {
CSEP: '.',
ISEP: '#',
NSEP: '::'
};
</script>
<script type='text/javascript' charset='utf-8' src='../js/highlight.pack.js'></script>
<script type='text/javascript' charset='utf-8' src='../js/y_app.js'></script>
</head>
<body>
<svg id='y_wait' class viewBox='0 0 90 90'></svg>
<div id='settings' class='hidden'></div>
<div id='y_list' class='d h'>
<header id='list_header'></header>
<nav id= 'list_nav' class='y_nav l_nav'>
<ul id='list_items'></ul>
</nav>
</div>
<div id='y_toc' class='f h'>
<header id='toc_header'></header>
<nav id= 'toc_nav' class='y_nav t_nav'>
<ol id='toc_items'></ol>
</nav>
</div>
<div id='y_main' tabindex='-1'>
<header id='y_header'>
<div id='y_menu'>
<a id='home_no_xhr' href='/'>Home</a> »
<a href='.'>Puma master</a> »
<a href='_index.html'>Index</a> »
<span class='title'><a id='t2_doc_top' href='#'>File: Stats ▲</a></span>
</div>
<a id='list_href' href="class_list.html"></a>
<div id='y_measure_em' class='y_measure'></div>
<div id='y_measure_vh' class='y_measure'></div>
<span id='y_measure_50pre' class='y_measure'><code>123456789_123456789_123456789_123456789_123456789_</code></span>
</header>
<div id='content' class='file'>
<h2>Accessing stats</h2>
<p>Stats can be accessed in two ways:</p>
<h3>control server</h3>
<p><code>$ pumactl stats</code> or <code>GET /stats</code></p>
<p><a href="https://github.com/puma/puma#controlstatus-server">Read more about <code>pumactl</code> and the control server in the README.</a>.</p>
<h3>Puma.stats</h3>
<p><a href="Puma.html#stats-class_method" title="Puma.stats (method)">Puma.stats</a> produces a JSON string. <a href="Puma.html#stats_hash-class_method" title="Puma.stats_hash (method)">Puma.stats_hash</a> produces a ruby hash.</p>
<h4>in single mode</h4>
<p>Invoke <a href="Puma.html#stats-class_method" title="Puma.stats (method)">Puma.stats</a> anywhere in runtime, e.g. in a rails initializer:</p>
<pre class="code ruby"><code class="ruby"><span class='comment'># config/initializers/puma_stats.rb
</span>
<span class='const'>Thread</span>.<span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
<span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span>
<span class='id identifier rubyid_sleep'>sleep</span> <span class='int'>30</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='const'><a href="Puma.html" title="Puma (module)">Puma</a></span>.<span class='id identifier rubyid_stats'><a href="Puma.html#stats-class_method" title="Puma.stats (method)">stats</a></span>
<span class='kw'>end</span>
<span class='kw'>end</span></code></pre>
<h4>in cluster mode</h4>
<p>Invoke <a href="Puma.html#stats-class_method" title="Puma.stats (method)">Puma.stats</a> from the master process</p>
<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
</span>
<span class='id identifier rubyid_before_fork'>before_fork</span> <span class='kw'>do</span>
<span class='const'>Thread</span>.<span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
<span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='const'><a href="Puma.html" title="Puma (module)">Puma</a></span>.<span class='id identifier rubyid_stats'><a href="Puma.html#stats-class_method" title="Puma.stats (method)">stats</a></span>
<span class='id identifier rubyid_sleep'>sleep</span> <span class='int'>30</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='kw'>end</span></code></pre>
<h2>Explanation of stats</h2>
<p><a href="Puma.html#stats-class_method" title="Puma.stats (method)">Puma.stats</a> returns different information and a different structure depending on if Puma is in single vs. cluster mode. There is one top-level attribute that is common to both modes:</p>
<ul>
<li>started_at: when Puma was started</li>
</ul>
<h3>single mode and individual workers in cluster mode</h3>
<p>When Puma runs in single mode, these stats are available at the top level. When Puma runs in cluster mode, these stats are available within the <code>worker_status</code> array in a hash labeled <code>last_status</code>, in an array of hashes where one hash represents each worker.</p>
<ul>
<li>backlog: requests that are waiting for an available thread to be available. if this is above 0, you need more capacity [always true?]</li>
<li>running: how many threads are spawned. A spawned thread may be busy processing a request or waiting for a new request. If <code>min_threads</code> and <code>max_threads</code> are set to the same number,
this will be a never-changing number (other than rare cases when a thread dies, etc).</li>
<li>pool_capacity: the number of requests that the server is capable of taking right now. For example, if the number is 5, then it means there are 5 threads sitting idle ready to take a request. If one request comes in, then the value would be 4 until it finishes processing. If the minimum threads allowed is zero, this number will still have a maximum value of the maximum threads allowed.</li>
<li>max_threads: the maximum number of threads Puma is configured to spool per worker</li>
<li>requests_count: the number of requests this worker has served since starting</li>
</ul>
<h3>cluster mode</h3>
<ul>
<li>phase: which phase of restart the process is in, during [phased restart])</li>
<li>workers: ??</li>
<li>booted_workers: how many workers currently running?</li>
<li>old_workers: ??</li>
<li>worker_status: array of hashes of info for each worker (see below)</li>
</ul>
<h3>worker status</h3>
<ul>
<li>started_at: when the worker started</li>
<li>pid: the process id of the worker process</li>
<li>index: each worker gets a number. if Puma is configured to have 3 workers, then this will be 0, 1, or 2</li>
<li>booted: if it's done booting [?]</li>
<li>last_checkin: Last time the worker responded to the master process' heartbeat check.</li>
<li>last_status: a hash of info about the worker's state handling requests. See the explanation for this in "single mode and individual workers in cluster mode" section above.</li>
</ul>
<h2>Examples</h2>
<p>Here are two example stats hashes produced by <a href="Puma.html#stats-class_method" title="Puma.stats (method)">Puma.stats</a>:</p>
<h3>single</h3>
<pre class="code json"><code class="json">{
"started_at": "2021-01-14T07:12:35Z",
"backlog": 0,
"running": 5,
"pool_capacity": 5,
"max_threads": 5,
"requests_count": 3
}
</code></pre>
<h3>cluster</h3>
<pre class="code json"><code class="json">{
"started_at": "2021-01-14T07:09:17Z",
"workers": 2,
"phase": 0,
"booted_workers": 2,
"old_workers": 0,
"worker_status": [
{
"started_at": "2021-01-14T07:09:24Z",
"pid": 64136,
"index": 0,
"phase": 0,
"booted": true,
"last_checkin": "2021-01-14T07:11:09Z",
"last_status": {
"backlog": 0,
"running": 5,
"pool_capacity": 5,
"max_threads": 5,
"requests_count": 2
}
},
{
"started_at": "2021-01-14T07:09:24Z",
"pid": 64137,
"index": 1,
"phase": 0,
"booted": true,
"last_checkin": "2021-01-14T07:11:09Z",
"last_status": {
"backlog": 0,
"running": 5,
"pool_capacity": 5,
"max_threads": 5,
"requests_count": 1
}
}
]
}
</code></pre>
<div id='footer'></div>
</div> <!-- content -->
</div> <!-- y_main -->
</body>
</html>