From fc01a4c5030cac2d6688171658f3a8e4781207d4 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 3 Oct 2023 13:59:59 +0100 Subject: [PATCH 01/10] refactor `newconnection` (no functional change) --- src/Connections.jl | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Connections.jl b/src/Connections.jl index 60d6eb9b7..4fbf8270a 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -451,22 +451,21 @@ function newconnection(::Type{T}, keepalive::Bool=true, kw...) where {T <: IO} connection_limit_warning(connection_limit) - return acquire( - getpool(pool, T), - (host, port, require_ssl_verification, keepalive, true); - forcenew=forcenew, - isvalid=c->connection_isvalid(c, Int(idle_timeout))) do - Connection(host, port, - idle_timeout, require_ssl_verification, keepalive, - connect_timeout > 0 ? - try_with_timeout(_ -> - getconnection(T, host, port; - require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...), - connect_timeout) : - getconnection(T, host, port; - require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...) - ) + function connect(timeout) + if timeout > 0 + try_with_timeout(timeout) do + getconnection(T, host, port; require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...) + end + else + getconnection(T, host, port; require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...) + end end + newconn() = Connection(host, port, idle_timeout, require_ssl_verification, keepalive, connect(connect_timeout)) + key = (host, port, require_ssl_verification, keepalive, true) + return acquire( + newconn, getpool(pool, T), key; + forcenew=forcenew, isvalid=c->connection_isvalid(c, Int(idle_timeout)), + ) end function releaseconnection(c::Connection{T}, reuse; pool::Union{Nothing, Pool}=nothing, kw...) where {T} From 58e9bd02c2c148e65af86ebff87fa9ebb8ef78a6 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 3 Oct 2023 18:17:51 +0100 Subject: [PATCH 02/10] Add function to report metrics for a `HTTP.Connection.Pool` --- src/Connections.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Connections.jl b/src/Connections.jl index 4fbf8270a..66a7826a2 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -384,6 +384,31 @@ const MBEDTLS_POOL = Ref{CPool{MbedTLS.SSLContext}}() const OPENSSL_POOL = Ref{CPool{OpenSSL.SSLStream}}() const OTHER_POOL = Lockable(IdDict{Type, CPool}()) +function metrics(pool::Nothing=nothing) + return Dict{Symbol,Dict{Symbol,Int}}( + :tcp => metrics(TCP_POOL[]), + :mbedtls => metrics(MBEDTLS_POOL[]), + :openssl => metrics(OPENSSL_POOL[]), + (Base.@lock OTHER_POOL.lock (Symbol(k) => metrics(v) for (k, v) in OTHER_POOL[]))..., + ) +end +function metrics(pool::Pool) + return Dict{Symbol,Dict{Symbol,Int}}( + :tcp => metrics(pool.tcp), + :mbedtls => metrics(pool.mbedtls), + :openssl => metrics(pool.openssl), + (Base.@lock pool.lock (Symbol(k) => metrics(v) for (k, v) in pool.other))..., + ) +end + +function metrics(cpool::CPool) + return Dict{Symbol,Int}( + :in_use => ConcurrentUtilities.Pools.permits(cpool), + :in_pool => ConcurrentUtilities.Pools.depth(cpool) + ) +end + + getpool(::Nothing, ::Type{Sockets.TCPSocket}) = TCP_POOL[] getpool(::Nothing, ::Type{MbedTLS.SSLContext}) = MBEDTLS_POOL[] getpool(::Nothing, ::Type{OpenSSL.SSLStream}) = OPENSSL_POOL[] From bf0bf766b6682a055aef43ee55df955753400f53 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 3 Oct 2023 18:48:51 +0100 Subject: [PATCH 03/10] fixup! Add function to report metrics for a `HTTP.Connection.Pool` --- src/Connections.jl | 62 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/src/Connections.jl b/src/Connections.jl index 66a7826a2..98cac95bc 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -384,30 +384,64 @@ const MBEDTLS_POOL = Ref{CPool{MbedTLS.SSLContext}}() const OPENSSL_POOL = Ref{CPool{OpenSSL.SSLStream}}() const OTHER_POOL = Lockable(IdDict{Type, CPool}()) +""" + HTTP.Connections.metrics() -> IdDict{Type,Metrics} + +Return a dictionary of connection metrics for the default pool. +These metrics are keyed by connection type. +""" function metrics(pool::Nothing=nothing) - return Dict{Symbol,Dict{Symbol,Int}}( - :tcp => metrics(TCP_POOL[]), - :mbedtls => metrics(MBEDTLS_POOL[]), - :openssl => metrics(OPENSSL_POOL[]), - (Base.@lock OTHER_POOL.lock (Symbol(k) => metrics(v) for (k, v) in OTHER_POOL[]))..., + return IdDict{Type,Metrics}( + Sockets.TCPSocket => Metrics(TCP_POOL[]), + MbedTLS.SSLContext => Metrics(MBEDTLS_POOL[]), + OpenSSL.SSLStream => Metrics(OPENSSL_POOL[]), + (Base.@lock OTHER_POOL.lock (k => Metrics(v) for (k, v) in OTHER_POOL[]))..., ) end + +""" + HTTP.Connections.metrics(pool::Pool) -> IdDict{Type,Metrics} + +Return a dictionary of connection metrics for the given `pool`, keyed by the connection +""" function metrics(pool::Pool) - return Dict{Symbol,Dict{Symbol,Int}}( - :tcp => metrics(pool.tcp), - :mbedtls => metrics(pool.mbedtls), - :openssl => metrics(pool.openssl), - (Base.@lock pool.lock (Symbol(k) => metrics(v) for (k, v) in pool.other))..., + return IdDict{Type,Metrics}( + Sockets.TCPSocket => Metrics(pool.tcp), + MbedTLS.SSLContext => Metrics(pool.mbedtls), + OpenSSL.SSLStream => Metrics(pool.openssl), + (Base.@lock pool.lock (k => Metrics(v) for (k, v) in pool.other))..., ) end -function metrics(cpool::CPool) - return Dict{Symbol,Int}( - :in_use => ConcurrentUtilities.Pools.permits(cpool), - :in_pool => ConcurrentUtilities.Pools.depth(cpool) +Base.@kwdef struct Metrics + limit::Int + in_use::Int + in_pool::Int +end + +""" + Metrics(cpool::$CPool) + +Metrics for the given connection pool: +- `limit`: the maximum number of connections allowed to be in-use at the same time. +- `in_use`: the number of connections currently in use. +- `in_pool`: the number of connections available for re-use. +""" +function Metrics(cpool::CPool) + return Metrics( + limit=ConcurrentUtilities.Pools.max(cpool), + in_use=ConcurrentUtilities.Pools.permits(cpool), + in_pool=ConcurrentUtilities.Pools.depth(cpool), ) end +function Base.show(io::IO, m::Metrics) + print(io, "Metrics(") + print(io, "limit=", m.limit) + print(io, ", in_use=", m.in_use) + print(io, ", in_pool=", m.in_pool) + print(io, ")") +end getpool(::Nothing, ::Type{Sockets.TCPSocket}) = TCP_POOL[] getpool(::Nothing, ::Type{MbedTLS.SSLContext}) = MBEDTLS_POOL[] From 8ae7f4ae75844baeafd516ac3e145c3df8bc3fd8 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 3 Oct 2023 22:46:18 +0100 Subject: [PATCH 04/10] fixup! refactor `newconnection` (no functional change) --- src/Connections.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Connections.jl b/src/Connections.jl index 98cac95bc..9998a9f4b 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -512,7 +512,7 @@ function newconnection(::Type{T}, connection_limit_warning(connection_limit) function connect(timeout) if timeout > 0 - try_with_timeout(timeout) do + try_with_timeout(timeout) do _ getconnection(T, host, port; require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...) end else From 85e7920bdc3bd417c1bb819c34f00ae258864965 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 3 Oct 2023 23:01:08 +0100 Subject: [PATCH 05/10] fixup! Add function to report metrics for a `HTTP.Connection.Pool` --- src/Connections.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Connections.jl b/src/Connections.jl index 9998a9f4b..770cd3b89 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -385,10 +385,9 @@ const OPENSSL_POOL = Ref{CPool{OpenSSL.SSLStream}}() const OTHER_POOL = Lockable(IdDict{Type, CPool}()) """ - HTTP.Connections.metrics() -> IdDict{Type,Metrics} + HTTP.Connections.metrics([nothing]) -> IdDict{Type,Metrics} -Return a dictionary of connection metrics for the default pool. -These metrics are keyed by connection type. +Return a dictionary of connection metrics, keyed by the connection type, for the default global pool. """ function metrics(pool::Nothing=nothing) return IdDict{Type,Metrics}( @@ -402,7 +401,7 @@ end """ HTTP.Connections.metrics(pool::Pool) -> IdDict{Type,Metrics} -Return a dictionary of connection metrics for the given `pool`, keyed by the connection +Return a dictionary of connection metrics, keyed by the connection type, for the given `pool`. """ function metrics(pool::Pool) return IdDict{Type,Metrics}( From 73a49cd2e40a345fc9a7954376ab23b5076a7bdc Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 4 Oct 2023 17:03:14 +0100 Subject: [PATCH 06/10] Add basic tests for `Connections.metrics` --- test/client.jl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/client.jl b/test/client.jl index 868ac8ded..b57d777db 100644 --- a/test/client.jl +++ b/test/client.jl @@ -342,6 +342,65 @@ end end end +@testset "Connections.metrics" begin + # Test that `metrics` function returns the expected values as we use / release connections. + # Initialise a pool, and check that it is empty and has the expected limit + pool = HTTP.Pool(3) + for (T, v) in HTTP.Connections.metrics(pool) + @test v.limit == 3 + @test v.in_pool == 0 + @test v.in_use == 0 + end + + TCP = Sockets.TCPSocket + # After a request, check the connection is put in the pool for reuse + HTTP.get("https://$httpbin/get"; pool=pool, socket_type_tls=TCP) + metrics = HTTP.Connections.metrics(pool) + @test metrics[TCP].in_pool == 1 + @test metrics[TCP].in_use == 0 + + # A second request should use this same connection and put it back again + HTTP.get("https://$httpbin/get"; pool=pool, socket_type_tls=TCP) + metrics = HTTP.Connections.metrics(pool) + @test metrics[TCP].in_pool == 1 + @test metrics[TCP].in_use == 0 + + # Force a new connection -- the one in the pool should remain there. + c1 = HTTP.Connections.newconnection(TCP, httpbin, ""; forcenew=true, connect_timeout=3, pool=pool) + metrics = HTTP.Connections.metrics(pool) + @test metrics[TCP].in_pool == 1 + @test metrics[TCP].in_use == 1 + + # Get another "new connection", since we didn't force new, this should use the one from the pool. + c2 = HTTP.Connections.newconnection(TCP, httpbin, ""; forcenew=false, connect_timeout=3, pool=pool) + metrics = HTTP.Connections.metrics(pool) + @test metrics[TCP].in_pool == 0 + @test metrics[TCP].in_use == 2 + + # Release the first connection back to the pool + HTTP.Connections.releaseconnection(c1, true; pool=pool) + metrics = HTTP.Connections.metrics(pool) + @test metrics[TCP].in_pool == 1 + @test metrics[TCP].in_use == 1 + + # Release the second connection but do not put back in the pool + HTTP.Connections.releaseconnection(c1, false; pool=pool) + metrics = HTTP.Connections.metrics(pool) + @test metrics[TCP].in_pool == 1 + @test metrics[TCP].in_use == 0 + + # Test another connection type + SSL = MbedTLS.SSLContext + @test metrics[SSL].limit == 3 + @test metrics[SSL].in_pool == 0 + @test metrics[SSL].in_use == 0 + HTTP.get("https://$httpbin/get"; pool=pool, socket_type_tls=SSL) + metrics = HTTP.Connections.metrics(pool) + @test metrics[SSL].limit == 3 + @test metrics[SSL].in_pool == 1 + @test metrics[SSL].in_use == 0 +end + @testset "Retry all resolved IP addresses" begin # See issue https://github.com/JuliaWeb/HTTP.jl/issues/672 # Bit tricky to test, but can at least be tested if localhost From 50d9ea3ece14f5d685f6d1c71307b029b2e9a991 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 4 Oct 2023 17:40:34 +0100 Subject: [PATCH 07/10] fixup! Add basic tests for `Connections.metrics` --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 565193acb..f39d175d9 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] CodecZlib = "0.7" -ConcurrentUtilities = "2.2" +ConcurrentUtilities = "2.3" ExceptionUnwrapping = "0.1" LoggingExtras = "0.4.9,1" MbedTLS = "0.6.8, 0.7, 1" From a05f346351d375382e1f6ced4f3a296fb1512e16 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 4 Oct 2023 17:41:04 +0100 Subject: [PATCH 08/10] TEMP add Manifest to allow tests to run --- Manifest.toml | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 000000000..962b05027 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,158 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.9.2" +manifest_format = "2.0" +project_hash = "c46963b102670aecccdbc101e6269347b2e132f5" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.BitFlags]] +git-tree-sha1 = "43b1a4a8f797c1cddadf60499a8a077d4af2cd2d" +uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35" +version = "0.1.7" + +[[deps.CodecZlib]] +deps = ["TranscodingStreams", "Zlib_jll"] +git-tree-sha1 = "9c209fb7536406834aa938fb149964b985de6c83" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.7.1" + +[[deps.ConcurrentUtilities]] +deps = ["Serialization", "Sockets"] +git-tree-sha1 = "584a4f8d88293ad5eaa5de6dff3e5066b9d47b14" +repo-rev = "npr-pool-size" +repo-url = "https://github.com/JuliaServices/ConcurrentUtilities.jl.git" +uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb" +version = "2.3.0" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.ExceptionUnwrapping]] +deps = ["Test"] +git-tree-sha1 = "e90caa41f5a86296e014e148ee061bd6c3edec96" +uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4" +version = "0.1.9" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.JLLWrappers]] +deps = ["Preferences"] +git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1" +uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +version = "1.4.1" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.LoggingExtras]] +deps = ["Dates", "Logging"] +git-tree-sha1 = "cedb76b37bc5a6c702ade66be44f831fa23c681e" +uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" +version = "1.0.0" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.MbedTLS]] +deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "Random", "Sockets"] +git-tree-sha1 = "03a9b9718f5682ecb107ac9f7308991db4ce395b" +uuid = "739be429-bea8-5141-9913-cc70e7f3736d" +version = "1.1.7" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.2+0" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2022.10.11" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.OpenSSL]] +deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"] +git-tree-sha1 = "51901a49222b09e3743c65b8847687ae5fc78eb2" +uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c" +version = "1.4.1" + +[[deps.OpenSSL_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "cae3153c7f6cf3f069a853883fd1919a6e5bab5b" +uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" +version = "3.0.9+0" + +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "7eb1686b4f04b82f96ed7a4ea5890a4f0c7a09f1" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.4.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.SimpleBufferStream]] +git-tree-sha1 = "874e8867b33a00e784c8a7e4b60afe9e037b74e1" +uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7" +version = "1.1.0" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.3" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.TranscodingStreams]] +deps = ["Random", "Test"] +git-tree-sha1 = "9a6ae7ed916312b41236fcef7e0af564ef934769" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.9.13" + +[[deps.URIs]] +git-tree-sha1 = "074f993b0ca030848b897beff716d93aca60f06a" +uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" +version = "1.4.2" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.13+0" From 2810eccc7c6fc70932e4f3930b139b8ef3460916 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 1 Nov 2023 16:36:05 +0000 Subject: [PATCH 09/10] 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 From 8ab792180a109fc47eb634ae6e0105ce3f585584 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 1 Nov 2023 17:15:26 +0000 Subject: [PATCH 10/10] Remove Manifest.toml now ConUtils 2.3 released --- Manifest.toml | 158 -------------------------------------------------- 1 file changed, 158 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index 9e6dd0b68..000000000 --- a/Manifest.toml +++ /dev/null @@ -1,158 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.9.2" -manifest_format = "2.0" -project_hash = "c46963b102670aecccdbc101e6269347b2e132f5" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" - -[[deps.Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[deps.BitFlags]] -git-tree-sha1 = "43b1a4a8f797c1cddadf60499a8a077d4af2cd2d" -uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35" -version = "0.1.7" - -[[deps.CodecZlib]] -deps = ["TranscodingStreams", "Zlib_jll"] -git-tree-sha1 = "9c209fb7536406834aa938fb149964b985de6c83" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.7.1" - -[[deps.ConcurrentUtilities]] -deps = ["Serialization", "Sockets"] -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" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[deps.ExceptionUnwrapping]] -deps = ["Test"] -git-tree-sha1 = "e90caa41f5a86296e014e148ee061bd6c3edec96" -uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4" -version = "0.1.9" - -[[deps.InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[deps.JLLWrappers]] -deps = ["Preferences"] -git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1" -uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.4.1" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[deps.Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[deps.LoggingExtras]] -deps = ["Dates", "Logging"] -git-tree-sha1 = "cedb76b37bc5a6c702ade66be44f831fa23c681e" -uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" -version = "1.0.0" - -[[deps.Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[deps.MbedTLS]] -deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "Random", "Sockets"] -git-tree-sha1 = "03a9b9718f5682ecb107ac9f7308991db4ce395b" -uuid = "739be429-bea8-5141-9913-cc70e7f3736d" -version = "1.1.7" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.2+0" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2022.10.11" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -version = "1.2.0" - -[[deps.OpenSSL]] -deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"] -git-tree-sha1 = "51901a49222b09e3743c65b8847687ae5fc78eb2" -uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c" -version = "1.4.1" - -[[deps.OpenSSL_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "cae3153c7f6cf3f069a853883fd1919a6e5bab5b" -uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "3.0.9+0" - -[[deps.Preferences]] -deps = ["TOML"] -git-tree-sha1 = "7eb1686b4f04b82f96ed7a4ea5890a4f0c7a09f1" -uuid = "21216c6a-2e73-6563-6e65-726566657250" -version = "1.4.0" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[deps.Random]] -deps = ["SHA", "Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[deps.SimpleBufferStream]] -git-tree-sha1 = "874e8867b33a00e784c8a7e4b60afe9e037b74e1" -uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7" -version = "1.1.0" - -[[deps.Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.3" - -[[deps.Test]] -deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[deps.TranscodingStreams]] -deps = ["Random", "Test"] -git-tree-sha1 = "9a6ae7ed916312b41236fcef7e0af564ef934769" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.9.13" - -[[deps.URIs]] -git-tree-sha1 = "074f993b0ca030848b897beff716d93aca60f06a" -uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" -version = "1.4.2" - -[[deps.UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+0"