From 2810eccc7c6fc70932e4f3930b139b8ef3460916 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 1 Nov 2023 16:36:05 +0000 Subject: [PATCH] Update ConcurrentUtilities --- Manifest.toml | 4 ++-- src/Connections.jl | 26 +++++++++++++------------- test/client.jl | 16 +++++++++------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 962b05027..9e6dd0b68 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -23,8 +23,8 @@ version = "0.7.1" [[deps.ConcurrentUtilities]] deps = ["Serialization", "Sockets"] -git-tree-sha1 = "584a4f8d88293ad5eaa5de6dff3e5066b9d47b14" -repo-rev = "npr-pool-size" +git-tree-sha1 = "8cfa272e8bdedfa88b6aefbbca7c19f1befac519" +repo-rev = "main" repo-url = "https://github.com/JuliaServices/ConcurrentUtilities.jl.git" uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb" version = "2.3.0" diff --git a/src/Connections.jl b/src/Connections.jl index 770cd3b89..ae9635def 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -350,10 +350,10 @@ end const CPool{T} = ConcurrentUtilities.Pool{ConnectionKeyType, Connection{T}} """ - HTTP.Pool(max::Int=HTTP.default_connection_limit[]) + HTTP.Pool(limit::Int=HTTP.default_connection_limit[]) Connection pool for managing the reuse of HTTP connections. -`max` controls the maximum number of concurrent connections allowed +`limit` controls the maximum number of concurrent connections allowed and defaults to the `HTTP.default_connection_limit` value. A pool can be passed to any of the `HTTP.request` methods via the `pool` keyword argument. @@ -364,17 +364,17 @@ struct Pool mbedtls::CPool{MbedTLS.SSLContext} openssl::CPool{OpenSSL.SSLStream} other::IdDict{Type, CPool} - max::Int + limit::Int end -function Pool(max::Union{Int, Nothing}=nothing) - max = something(max, default_connection_limit[]) +function Pool(limit::Union{Int, Nothing}=nothing) + limit = something(limit, default_connection_limit[]) return Pool(ReentrantLock(), - CPool{Sockets.TCPSocket}(max), - CPool{MbedTLS.SSLContext}(max), - CPool{OpenSSL.SSLStream}(max), + CPool{Sockets.TCPSocket}(limit), + CPool{MbedTLS.SSLContext}(limit), + CPool{OpenSSL.SSLStream}(limit), IdDict{Type, CPool}(), - max, + limit, ) end @@ -428,9 +428,9 @@ Metrics for the given connection pool: """ function Metrics(cpool::CPool) return Metrics( - limit=ConcurrentUtilities.Pools.max(cpool), - in_use=ConcurrentUtilities.Pools.permits(cpool), - in_pool=ConcurrentUtilities.Pools.depth(cpool), + limit=ConcurrentUtilities.Pools.limit(cpool), + in_use=ConcurrentUtilities.Pools.in_use(cpool), + in_pool=ConcurrentUtilities.Pools.in_pool(cpool), ) end @@ -457,7 +457,7 @@ function getpool(pool::Pool, ::Type{T})::CPool{T} where {T} elseif T === OpenSSL.SSLStream return pool.openssl else - return Base.@lock pool.lock get!(() -> CPool{T}(pool.max), pool.other, T) + return Base.@lock pool.lock get!(() -> CPool{T}(pool.limit), pool.other, T) end end diff --git a/test/client.jl b/test/client.jl index b57d777db..6bceb3740 100644 --- a/test/client.jl +++ b/test/client.jl @@ -14,11 +14,13 @@ using InteractiveUtils: @which using ConcurrentUtilities # test we can adjust default_connection_limit -for x in (10, 12) - HTTP.set_default_connection_limit!(x) - @test HTTP.Connections.TCP_POOL[].max == x - @test HTTP.Connections.MBEDTLS_POOL[].max == x - @test HTTP.Connections.OPENSSL_POOL[].max == x +@testset "set_default_connection_limit!" begin + for x in (10, 12) + HTTP.set_default_connection_limit!(x) + @test HTTP.Connections.TCP_POOL[].limit == x + @test HTTP.Connections.MBEDTLS_POOL[].limit == x + @test HTTP.Connections.OPENSSL_POOL[].limit == x + end end @testset "@client macro" begin @@ -325,11 +327,11 @@ end end @testset "connect_timeout does not include the time needed to acquire a connection from the pool" begin - connection_limit = HTTP.Connections.TCP_POOL[].max + connection_limit = HTTP.Connections.TCP_POOL[].limit try dummy_conn = HTTP.Connection(Sockets.TCPSocket()) HTTP.set_default_connection_limit!(1) - @assert HTTP.Connections.TCP_POOL[].max == 1 + @assert HTTP.Connections.TCP_POOL[].limit == 1 # drain the pool acquire(()->dummy_conn, HTTP.Connections.TCP_POOL[], HTTP.Connections.connectionkey(dummy_conn)) # Put it back in 10 seconds