Skip to content

Commit 3fc0971

Browse files
feat: bump default connection pool size limit to minimum of 99
1 parent 1d53fee commit 3fc0971

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lib/openai/client.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ def initialize(
104104
organization: ENV["OPENAI_ORG_ID"],
105105
project: ENV["OPENAI_PROJECT_ID"],
106106
base_url: ENV["OPENAI_BASE_URL"],
107-
max_retries: OpenAI::Client::DEFAULT_MAX_RETRIES,
108-
timeout: OpenAI::Client::DEFAULT_TIMEOUT_IN_SECONDS,
109-
initial_retry_delay: OpenAI::Client::DEFAULT_INITIAL_RETRY_DELAY,
110-
max_retry_delay: OpenAI::Client::DEFAULT_MAX_RETRY_DELAY
107+
max_retries: self.class::DEFAULT_MAX_RETRIES,
108+
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
109+
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
110+
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
111111
)
112112
base_url ||= "https://api.openai.com/v1"
113113

lib/openai/internal/transport/pooled_net_requester.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class PooledNetRequester
1111
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
1212
KEEP_ALIVE_TIMEOUT = 30
1313

14+
DEFAULT_MAX_CONNECTIONS = [Etc.nprocessors, 99].max
15+
1416
class << self
1517
# @api private
1618
#
@@ -184,7 +186,7 @@ def execute(request)
184186
# @api private
185187
#
186188
# @param size [Integer]
187-
def initialize(size: Etc.nprocessors)
189+
def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
188190
@mutex = Mutex.new
189191
@size = size
190192
@pools = {}

rbi/openai/internal/transport/pooled_net_requester.rbi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module OpenAI
2222
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
2323
KEEP_ALIVE_TIMEOUT = 30
2424

25+
DEFAULT_MAX_CONNECTIONS = T.let(T.unsafe(nil), Integer)
26+
2527
class << self
2628
# @api private
2729
sig { params(url: URI::Generic).returns(Net::HTTP) }
@@ -66,7 +68,9 @@ module OpenAI
6668

6769
# @api private
6870
sig { params(size: Integer).returns(T.attached_class) }
69-
def self.new(size: Etc.nprocessors)
71+
def self.new(
72+
size: OpenAI::Internal::Transport::PooledNetRequester::DEFAULT_MAX_CONNECTIONS
73+
)
7074
end
7175
end
7276
end

sig/openai/internal/transport/pooled_net_requester.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module OpenAI
1515

1616
KEEP_ALIVE_TIMEOUT: 30
1717

18+
DEFAULT_MAX_CONNECTIONS: Integer
19+
1820
def self.connect: (URI::Generic url) -> top
1921

2022
def self.calibrate_socket_timeout: (top conn, Float deadline) -> void

0 commit comments

Comments
 (0)