graphiti 1.5.3 → 1.6.1

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: 6e73347300b459ef189141f41dc56748767b8dfedc7b6b27965da4fa338cdd90
4
- data.tar.gz: 2c3dc9a6dc41aa072360fb20c79ec11d7b9663334f023369f32e0822f98f640b
3
+ metadata.gz: db292ffdb5b46b46d42e012cd68acc342649e28fc6f9cf7c5769db4e0b4bda21
4
+ data.tar.gz: 2ae2161355c2dccf3fc833831f39eff69639967885e81f25594b75de4fcaca22
5
5
  SHA512:
6
- metadata.gz: 8144b492f5a20b239caf5616d35a4022cb7df4acc56af08feeae987fdf5ab4157c713f7275ee67947cc993bc8618aeee4808de20da7c27020b79bb5aa4151919
7
- data.tar.gz: 116b84208d8095eb7f07ba965a3fe94dcd683568bc1c658edd0be8ae635a2e45e4edcfa109dec80723698b502be6964ea7caae2930ff0f53f0b31db05803a16e
6
+ metadata.gz: 57306d14268453ee0629e952ff85f23becb6bb2f76b9f238bd7f9030214181020baa3ea227f23d23225cb8e67398a693d1662c2f4d2e64a67629b46a8b47cf16
7
+ data.tar.gz: a60d925e5fedb2fe79813d128cc5a6f2fb957bce509372c4b22456b04eab2f795bdbd1d1937cdf1176883338845567648e84cc8d7dd03844b0cafefb2f2d140f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  graphiti changelog
2
2
 
3
+ ## [1.6.1](https://github.com/graphiti-api/graphiti/compare/v1.6.0...v1.6.1) (2024-03-22)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * correct thread-pool mutex logic which was causing a deadlock ([0400ab0](https://github.com/graphiti-api/graphiti/commit/0400ab0d97a1382b66b5295fdc7aa7db680e77cc))
9
+
10
+ # [1.6.0](https://github.com/graphiti-api/graphiti/compare/v1.5.3...v1.6.0) (2024-03-20)
11
+
12
+
13
+ ### Features
14
+
15
+ * add thread pool and concurrency_max_threads configuration option ([#470](https://github.com/graphiti-api/graphiti/issues/470)) ([697d761](https://github.com/graphiti-api/graphiti/commit/697d76172adec24cd7e7522300c8335233fdcc36))
16
+
3
17
  ## [1.5.3](https://github.com/graphiti-api/graphiti/compare/v1.5.2...v1.5.3) (2024-03-18)
4
18
 
5
19
 
@@ -8,6 +8,20 @@ module Graphiti
8
8
  # Defaults to false OR if classes are cached (Rails-only)
9
9
  attr_accessor :concurrency
10
10
 
11
+ # This number must be considered in accordance with the database
12
+ # connection pool size configured in `database.yml`. The connection
13
+ # pool should be large enough to accommodate both the foreground
14
+ # threads (ie. web server or job worker threads) and background
15
+ # threads. For each process, Graphiti will create one global
16
+ # executor that uses this many threads to sideload resources
17
+ # asynchronously. Thus, the pool size should be at least
18
+ # `thread_count + concurrency_max_threads + 1`. For example, if your
19
+ # web server has a maximum of 3 threads, and
20
+ # `concurrency_max_threads` is set to 4, then your pool size should
21
+ # be at least 8.
22
+ # @return [Integer] Maximum number of threads to use when fetching sideloads concurrently
23
+ attr_accessor :concurrency_max_threads
24
+
11
25
  attr_accessor :respond_to
12
26
  attr_accessor :context_for_endpoint
13
27
  attr_accessor :links_on_demand
@@ -26,6 +40,7 @@ module Graphiti
26
40
  def initialize
27
41
  @raise_on_missing_sideload = true
28
42
  @concurrency = false
43
+ @concurrency_max_threads = 4
29
44
  @respond_to = [:json, :jsonapi, :xml]
30
45
  @links_on_demand = false
31
46
  @pagination_links_on_demand = false
@@ -2,6 +2,23 @@ module Graphiti
2
2
  class Scope
3
3
  attr_accessor :object, :unpaginated_object
4
4
  attr_reader :pagination
5
+
6
+ @thread_pool_executor_mutex = Mutex.new
7
+
8
+ def self.thread_pool_executor
9
+ return @thread_pool_executor if @thread_pool_executor
10
+
11
+ concurrency = Graphiti.config.concurrency_max_threads || 4
12
+ @thread_pool_executor ||= @thread_pool_executor_mutex.synchronize do
13
+ Concurrent::ThreadPoolExecutor.new(
14
+ min_threads: 0,
15
+ max_threads: concurrency,
16
+ max_queue: concurrency * 4,
17
+ fallback_policy: :caller_runs
18
+ )
19
+ end
20
+ end
21
+
5
22
  def initialize(object, resource, query, opts = {})
6
23
  @object = object
7
24
  @resource = resource
@@ -49,7 +66,7 @@ module Graphiti
49
66
  @resource.adapter.close if concurrent
50
67
  }
51
68
  if concurrent
52
- promises << Concurrent::Promise.execute(&resolve_sideload)
69
+ promises << Concurrent::Promise.execute(executor: self.class.thread_pool_executor, &resolve_sideload)
53
70
  else
54
71
  resolve_sideload.call
55
72
  end
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.5.3"
2
+ VERSION = "1.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-18 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable