redis_queued_locks 1.3.1 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cac51b8b6c2a4986c188d7b419e11a282c4a18d6a32689000a2c9127f77eec3
4
- data.tar.gz: d159e30574e503a714081dfda22d9085553818573ad968f745e302efe93edfde
3
+ metadata.gz: 448f8b89e4a34bb2543b55d46877d80f76cf8e4b5d07735486f53eb1edb37432
4
+ data.tar.gz: 4fbefadd9a162ab298b100bca38387045c65c89918ffd70c3f4aa418aa72d22a
5
5
  SHA512:
6
- metadata.gz: 6ee000a0470297832a593a8719a192feb5fdf583003d49f8dfb3335dad4c63aff45730cc8d4481a02eb41f629e60d929349fcc1842025117bd5b35304a09c8cd
7
- data.tar.gz: c7e52ef09012e29a2ac1495fedc287c7a51c5fee8ceac466f78d5de548e8231b7a5c8fc29626db28ca82629ac0294b4ded991cbf5902f97a76619279bed4e353
6
+ metadata.gz: 738c503d6189ca4673d1bc5af829066378654a070b78691ae7d1001e832795dbb91f1cde3e89252ff6b9831a659daf517eea1ea2ab721101c9140afe16b44974
7
+ data.tar.gz: cb2b4893238e55688b01c56f5f0004217d206122d5ae5ef3a0ea8f2d206323442e4c10bf78f3d504f947795864decc712f5385448b205151ccfe7ca39ab9ea0a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0] - 2024-05-13
4
+ ### Added
5
+ - `#lock`/`#lock!`: reduced memory allocaiton during `:meta` attribute type checking;
6
+ ### Changed
7
+ - More accurate time analyzis operations;
8
+
3
9
  ## [1.3.1] - 2024-05-10
4
10
  ### Fixed
5
11
  - `:meta` attribute type validation of `#lock`/`#lock!` was incorrect;
data/README.md CHANGED
@@ -1086,7 +1086,7 @@ rql.clear_dead_requests(dead_ttl: 60 * 60 * 1000) # 1 hour in milliseconds
1086
1086
  (`:wait_for_lock` (default), `:work_through`, `:extendable_work_through`, `:dead_locking`);
1087
1087
  - by default behavior (`:wait_for_lock`) your lock obtaining process will work in a classic way (limits, retries, etc);
1088
1088
  - `:work_through`, `:extendable_work_through` works with limits too (timeouts, delays, etc), but the decision of
1089
- "is your lock are obtained or not" is made as you work with **reentrant locks** (your process continues to use the lock without/without
1089
+ "is your lock are obtained or not" is made as you work with **reentrant locks** (your process continues to use the lock without/with
1090
1090
  lock's TTL accordingly);
1091
1091
  - for current implementation details check:
1092
1092
  - [Configuration](#configuration) documentation: see `config.default_conflict_strategy` config docs;
@@ -49,7 +49,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
49
49
  initial_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :millisecond)
50
50
 
51
51
  if block_given?
52
- timeout = ((ttl - ttl_shift) / 1000.0).yield_self do |time|
52
+ timeout = ((ttl - ttl_shift) / 1_000.0).yield_self do |time|
53
53
  # NOTE: time in <seconds> cuz Ruby's Timeout requires <seconds>
54
54
  (time < 0) ? 0.0 : time
55
55
  end
@@ -94,7 +94,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
94
94
  #
95
95
  # @api private
96
96
  # @since 1.0.0
97
- # @version 1.3.1
97
+ # @version 1.4.0
98
98
  def acquire_lock(
99
99
  redis,
100
100
  lock_name,
@@ -132,7 +132,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
132
132
  end
133
133
 
134
134
  # Step 0.2: prevent :meta incompatabiltiies (structure)
135
- if meta.is_a?(::Hash) && (meta.keys.any? do |key|
135
+ if meta.is_a?(::Hash) && (meta.any? do |key, _value|
136
136
  key == 'acq_id' ||
137
137
  key == 'ts' ||
138
138
  key == 'ini_ttl' ||
@@ -198,7 +198,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
198
198
 
199
199
  # Step 2: try to lock with timeout
200
200
  with_acq_timeout(timeout, lock_key, raise_errors, on_timeout: acq_dequeue) do
201
- acq_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
201
+ acq_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
202
202
 
203
203
  # Step 2.1: cyclically try to obtain the lock
204
204
  while acq_process[:should_try]
@@ -241,8 +241,8 @@ module RedisQueuedLocks::Acquier::AcquireLock
241
241
  meta
242
242
  ) => { ok:, result: }
243
243
 
244
- acq_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
245
- acq_time = ((acq_end_time - acq_start_time) * 1_000).ceil(2)
244
+ acq_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
245
+ acq_time = ((acq_end_time - acq_start_time) / 1_000.0).ceil(2)
246
246
 
247
247
  # Step X: save the intermediate results to the result observer
248
248
  acq_process[:result] = result
@@ -403,10 +403,10 @@ module RedisQueuedLocks::Acquier::AcquireLock
403
403
  # Step 3.a: acquired successfully => run logic or return the result of acquirement
404
404
  if block_given?
405
405
  begin
406
- yield_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
406
+ yield_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
407
407
 
408
408
  ttl_shift = (
409
- (yield_time - acq_process[:acq_end_time]) * 1000 -
409
+ (yield_time - acq_process[:acq_end_time]) / 1_000.0 -
410
410
  RedisQueuedLocks::Resource::REDIS_TIMESHIFT_ERROR
411
411
  ).ceil(2)
412
412
 
@@ -431,9 +431,11 @@ module RedisQueuedLocks::Acquier::AcquireLock
431
431
  &block
432
432
  )
433
433
  ensure
434
- acq_process[:rel_time] = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
434
+ acq_process[:rel_time] = ::Process.clock_gettime(
435
+ ::Process::CLOCK_MONOTONIC, :microsecond
436
+ )
435
437
  acq_process[:hold_time] = (
436
- (acq_process[:rel_time] - acq_process[:acq_end_time]) * 1000
438
+ (acq_process[:rel_time] - acq_process[:acq_end_time]) / 1_000.0
437
439
  ).ceil(2)
438
440
 
439
441
  if acq_process[:result][:process] == :extendable_conflict_work_through ||
@@ -15,7 +15,7 @@ module RedisQueuedLocks::Acquier::ClearDeadRequests
15
15
  # @api private
16
16
  # @since 1.0.0
17
17
  def clear_dead_requests(redis_client, scan_size, dead_ttl, logger, instrumenter, instrument)
18
- dead_score = RedisQueuedLocks::Resource.acquier_dead_score(dead_ttl / 1000.0)
18
+ dead_score = RedisQueuedLocks::Resource.acquier_dead_score(dead_ttl / 1_000.0)
19
19
 
20
20
  result = Set.new.tap do |processed_queues|
21
21
  redis_client.with do |rconn|
@@ -28,12 +28,13 @@ module RedisQueuedLocks::Acquier::ReleaseAllLocks
28
28
  #
29
29
  # @api private
30
30
  # @since 1.0.0
31
+ # @version 1.4.0
31
32
  def release_all_locks(redis, batch_size, logger, instrumenter, instrument)
32
- rel_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
33
+ rel_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
33
34
  fully_release_all_locks(redis, batch_size) => { ok:, result: }
34
35
  time_at = Time.now.to_f
35
- rel_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
36
- rel_time = ((rel_end_time - rel_start_time) * 1_000).ceil(2)
36
+ rel_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
37
+ rel_time = ((rel_end_time - rel_start_time) / 1_000).ceil(2)
37
38
 
38
39
  run_non_critical do
39
40
  instrumenter.notify('redis_queued_locks.explicit_all_locks_release', {
@@ -28,15 +28,16 @@ module RedisQueuedLocks::Acquier::ReleaseLock
28
28
  #
29
29
  # @api private
30
30
  # @since 1.0.0
31
+ # @version 1.4.0
31
32
  def release_lock(redis, lock_name, instrumenter, logger)
32
33
  lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name)
33
34
  lock_key_queue = RedisQueuedLocks::Resource.prepare_lock_queue(lock_name)
34
35
 
35
- rel_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
36
+ rel_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
36
37
  fully_release_lock(redis, lock_key, lock_key_queue) => { ok:, result: }
37
38
  time_at = Time.now.to_f
38
- rel_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
39
- rel_time = ((rel_end_time - rel_start_time) * 1_000).ceil(2)
39
+ rel_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
40
+ rel_time = ((rel_end_time - rel_start_time) / 1_000).ceil(2)
40
41
 
41
42
  run_non_critical do
42
43
  instrumenter.notify('redis_queued_locks.explicit_lock_release', {
@@ -5,6 +5,6 @@ module RedisQueuedLocks
5
5
  #
6
6
  # @api public
7
7
  # @since 0.0.1
8
- # @version 1.3.1
9
- VERSION = '1.3.1'
8
+ # @version 1.4.0
9
+ VERSION = '1.4.0'
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_queued_locks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client