prometheus-client-mmap 0.27.0-x86_64-darwin → 0.28.1-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f86b5f02214133576b8d461eb030c3da8c256d6f1e31693621372829a6b4102
4
- data.tar.gz: 5cbf7b696d070a4d4038ea2d6cc459d19818403cde3f1134fa051b6a6e969361
3
+ metadata.gz: 89d04a2d72d09caa22e308eb773c46fc0b68e63d12fae738f0972776967967cd
4
+ data.tar.gz: 9e7855cef20f44b8c9447bd166e43e9835d824a7278e90f1d102a0d9b29312fb
5
5
  SHA512:
6
- metadata.gz: c9b816ec1e29402adba83cbbd1c8d5928fec70d6345094301312eae26cef94f8fcdb183743d938d549453f66c7356d7b5b51e72b16b04e8c97c7c5053830c218
7
- data.tar.gz: eb5c2fc9d0504520b8cb64bfe32c184e408de8fdf78b29c43aad9ffa41791497b3c714f33dee94afbdfbe81ffcfa429c974b4f213a023360f190fc7a27f512a1
6
+ metadata.gz: 53fd89172270e5c6540e7d14fb7faee2650b50c89e20f47cc9f51f45987202dccfb6a361267dfe555e66118830750e30b774005a069e30a6a8630b34029f31d7
7
+ data.tar.gz: 0e2027b2855e698e8e8aa57076c8d04becbe9e0e56e77ea36c372cf90aa21ffe1904bfd1bea7222d6e07342d74056fedfe3951edc71c28b72ad9289c72ab0559
data/README.md CHANGED
@@ -241,8 +241,8 @@ To use the C extension, set the environment variable
241
241
 
242
242
  ### PID cardinality
243
243
 
244
- In multiprocess setup e.g. running under Unicorn, having worker process restart often can
245
- lead to performance problems when proccesing metric files. By default each process using
244
+ In multiprocess setup e.g. running under Unicorn or Puma, having worker process restart often
245
+ can lead to performance problems when proccesing metric files. By default each process using
246
246
  Prometheus metrics will create a set of files based on that process PID. With high worker
247
247
  churn this will lead to creation of thousands of files and in turn will cause very noticable
248
248
  slowdown when displaying metrics
@@ -250,14 +250,20 @@ slowdown when displaying metrics
250
250
  To reduce this problem, a surrogate process id can be used. Set of all such IDs needs
251
251
  have low cardinality, and each process id must be unique among all running process.
252
252
 
253
- For Unicorn a worker id/number can be used to greatly speedup the metrics rendering.
253
+ For Unicorn and Puma a worker id/number can be used to greatly speedup the metrics rendering.
254
254
 
255
- To use it add this line to your `configure` block:
255
+ If you are using Unicorn, add this line to your `configure` block:
256
256
 
257
257
  ```ruby
258
258
  config.pid_provider = Prometheus::Client::Support::Unicorn.method(:worker_pid_provider)
259
259
  ```
260
260
 
261
+ If you are using Puma, add this line to your `configure` block:
262
+
263
+ ```ruby
264
+ config.pid_provider = Prometheus::Client::Support::Puma.method(:worker_pid_provider)
265
+ ```
266
+
261
267
  ## Tools
262
268
 
263
269
  ### `bin/parse`
@@ -189,12 +189,6 @@ static void mm_free(mm_ipc *i_mm) {
189
189
  }
190
190
 
191
191
  if (i_mm->t->path != (char *)-1) {
192
- if (i_mm->t->real < i_mm->t->len && i_mm->t->vscope != MAP_PRIVATE &&
193
- truncate(i_mm->t->path, i_mm->t->real) == -1) {
194
- free(i_mm->t->path);
195
- free(i_mm);
196
- rb_raise(rb_eTypeError, "truncate");
197
- }
198
192
  free(i_mm->t->path);
199
193
  }
200
194
  }
@@ -414,10 +408,6 @@ VALUE mm_unmap(VALUE obj) {
414
408
  }
415
409
 
416
410
  if (i_mm->t->path != (char *)-1) {
417
- if (i_mm->t->real < i_mm->t->len && i_mm->t->vscope != MAP_PRIVATE &&
418
- truncate(i_mm->t->path, i_mm->t->real) == -1) {
419
- rb_raise(rb_eTypeError, "truncate");
420
- }
421
411
  free(i_mm->t->path);
422
412
  }
423
413
 
@@ -224,16 +224,6 @@ impl InnerMmap {
224
224
  }
225
225
  }
226
226
 
227
- /// Truncate the mmapped file to the end of the metrics data.
228
- pub fn truncate_file(&mut self) -> Result<()> {
229
- // CAST: no-op on 64-bit, widening on 32-bit.
230
- let trunc_len = self.len as u64;
231
-
232
- self.file
233
- .set_len(trunc_len)
234
- .map_err(|e| MmapError::legacy(format!("truncate: {e}"), RubyError::Type))
235
- }
236
-
237
227
  /// Load the `used` header containing the size of the metrics data written.
238
228
  pub fn load_used(&self) -> Result<u32> {
239
229
  match read_u32(self.map.as_ref(), 0) {
@@ -225,9 +225,6 @@ impl MmapedFile {
225
225
  let rs_self = &*rb_self;
226
226
 
227
227
  rs_self.inner_mut(|inner| {
228
- // truncate file to actual used size
229
- inner.truncate_file()?;
230
-
231
228
  // We are about to release the backing mmap for Ruby's String
232
229
  // objects. If Ruby attempts to read from them the program will
233
230
  // segfault. We update the length of all Strings to zero so Ruby
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,44 @@
1
+ module Prometheus
2
+ module Client
3
+ module Support
4
+ module Puma
5
+ extend self
6
+
7
+ def worker_pid_provider
8
+ wid = worker_id
9
+ if wid = worker_id
10
+ wid
11
+ else
12
+ "process_id_#{Process.pid}"
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def object_based_worker_id
19
+ return unless defined?(::Puma::Cluster::Worker)
20
+
21
+ workers = ObjectSpace.each_object(::Puma::Cluster::Worker)
22
+ return if workers.nil?
23
+
24
+ workers_first = workers.first
25
+ workers_first.index unless workers_first.nil?
26
+ end
27
+
28
+ def program_name
29
+ $PROGRAM_NAME
30
+ end
31
+
32
+ def worker_id
33
+ if matchdata = program_name.match(/puma.*cluster worker ([0-9]+):/)
34
+ "puma_#{matchdata[1]}"
35
+ elsif object_worker_id = object_based_worker_id
36
+ "puma_#{object_worker_id}"
37
+ elsif program_name.include?('puma')
38
+ 'puma_master'
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.27.0'.freeze
3
+ VERSION = '0.28.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-client-mmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.1
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Tobias Schmidt
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-07-31 00:00:00.000000000 Z
14
+ date: 2023-10-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rb_sys
@@ -197,6 +197,7 @@ files:
197
197
  - lib/prometheus/client/registry.rb
198
198
  - lib/prometheus/client/simple_value.rb
199
199
  - lib/prometheus/client/summary.rb
200
+ - lib/prometheus/client/support/puma.rb
200
201
  - lib/prometheus/client/support/unicorn.rb
201
202
  - lib/prometheus/client/uses_value_type.rb
202
203
  - lib/prometheus/client/version.rb