network_resiliency 0.7.14 → 0.8.0

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: 8515a542f0e3d22b8e562187dcc23325c8c89866c2e708cf540cb73894195471
4
- data.tar.gz: 30cd44b2ad019321587b8d29f0afc28cde9070f88ded257799e1bcb1aa3dc7e1
3
+ metadata.gz: a2a0b6dd58bb024a582f951fd5aa8105506a8c2ffee8dddac284128a09fc844a
4
+ data.tar.gz: 7b978707f7788382cca10421190942c7395423d363eb222ddb0e5d1f5f1d734d
5
5
  SHA512:
6
- metadata.gz: 0530fb98688ef75f2cccd2bbe4e75c835bbf20ca3cbdec307c26f9ed9bc04462361867f96ecbf001dc81c36675b1024dca2e09f80b0fa8e71fc623d0540849d2
7
- data.tar.gz: 2de979e7c792a32f7993625a529d31a7b35616c51c17aedea97acd2884f0a589144ec2bbb81cf6cb0f8a50591c3bc414cff7e3253643cb46c266ecf0cb8d2458
6
+ metadata.gz: ae2e38bf103409e575f31245634fca438992e9a50415b5c1d0bfa16e75016513a378ad2f0a9c2adef3c22a6392ef2ed1d9da67c26fff745b799bad2c83806e74
7
+ data.tar.gz: aad0e97f32f64ecb254ee5095375119bf0ff307ab578a7566280e93994c6a59ea3eb3d135a2e1a89bef4ae3f90d4ab94af149dd274594c9f1bcda76f777c2b0e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### v0.8.0 (2024-03-12)
2
+ - secondary timeout
3
+ - cover http socket error
4
+
5
+ ### v0.7.15 (2024-03-08)
6
+ - higher def timeouts
7
+
1
8
  ### v0.7.14 (2024-03-07)
2
9
  - lower dynamic timeout
3
10
  - timeout-min
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.7.14)
4
+ network_resiliency (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,10 +6,11 @@ module NetworkResiliency
6
6
  extend self
7
7
 
8
8
  ERRORS = [
9
- Timeout::Error,
10
9
  IOError,
11
- SystemCallError,
12
10
  (OpenSSL::OpenSSLError if defined?(OpenSSL::SSL)),
11
+ SocketError,
12
+ SystemCallError,
13
+ Timeout::Error,
13
14
  ].compact
14
15
 
15
16
  REQUEST_TIMEOUT_HEADER = "X-Request-Timeout"
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.7.14"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -21,7 +21,7 @@ module NetworkResiliency
21
21
  ADAPTERS = [ :http, :faraday, :redis, :mysql, :postgres, :rails ].freeze
22
22
  DEFAULT_TIMEOUT_MIN = 10 # ms
23
23
  MODE = [ :observe, :resilient ].freeze
24
- RESILIENCY_THRESHOLD = 300
24
+ RESILIENCY_THRESHOLD = 100
25
25
  SAMPLE_RATE = {
26
26
  timeout: 0.1,
27
27
  stats: 0.1,
@@ -271,7 +271,7 @@ module NetworkResiliency
271
271
  key = [ adapter, action, destination ].join(":")
272
272
  stats = StatsEngine.add(key, duration)
273
273
 
274
- if stats.n > RESILIENCY_THRESHOLD * 4
274
+ if stats.n > RESILIENCY_THRESHOLD * 5
275
275
  # downsample to age out old stats
276
276
  stats.scale!(50)
277
277
  end
@@ -338,8 +338,17 @@ module NetworkResiliency
338
338
  destination: destination,
339
339
  }
340
340
 
341
- # p99 = (stats.avg + stats.stdev * 2).order_of_magnitude(ceil: true)
342
- p99 = (stats.avg + stats.stdev * 3).power_ceil
341
+ p99 = (stats.avg + stats.stdev * 3)
342
+
343
+ # add margin of error / normalize
344
+ p99 = if stats.n >= RESILIENCY_THRESHOLD * 2
345
+ p99.power_ceil
346
+ else
347
+ # larger margin of error
348
+ p99.order_of_magnitude(ceil: true)
349
+ end
350
+
351
+ # enforce minimum timeout
343
352
  p99 = [ p99, timeout_min ].max
344
353
 
345
354
  timeouts = []
@@ -350,11 +359,16 @@ module NetworkResiliency
350
359
  if p99 < max
351
360
  timeouts << p99
352
361
 
353
- # fallback attempt
354
- if max - p99 > p99
362
+ # make a second, more lenient attempt
363
+
364
+ if p99 * 100 < max
365
+ # max is excessively high
366
+ timeouts << p99 * 100
367
+ elsif p99 * 10 < max
355
368
  # use remaining time for second attempt
356
369
  timeouts << max - p99
357
370
  else
371
+ # max is smallish
358
372
  timeouts << max
359
373
 
360
374
  NetworkResiliency.statsd&.increment(
@@ -376,10 +390,8 @@ module NetworkResiliency
376
390
  else
377
391
  timeouts << p99
378
392
 
379
- # timeouts << p99 * 10 if NetworkResiliency.mode(action) == :resolute
380
-
381
- # unbounded second attempt
382
- timeouts << nil
393
+ # second attempt
394
+ timeouts << p99 * 100
383
395
 
384
396
  NetworkResiliency.statsd&.increment(
385
397
  "network_resiliency.timeout.missing",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network_resiliency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.14
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-07 00:00:00.000000000 Z
11
+ date: 2024-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug