Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ By default Julia 1.12 starts with just one thread. The closer to `@async` we get
However, it is unlikely Julia will be used this way in the real world.

```
╭──────────────────────────────────┬─────────────────┬─────────────┬──────────┬────────────┬──────────────┬─────────┬──────┬──────╮
│ Benchmark │ N │ Memory │ Allocations │ Duration │ Throughput │ Avg duration │ Std-dev │ Min │ Max │
│ │ calls │ MiB │ │ s │ calls/s │ μs │ μs │ μs │ μs │
├──────────────────────────────────┼─────────────────┼─────────────┼──────────┼────────────┼──────────────┼─────────┼──────┼──────┤
│ workload_smol │ 94000 │ 3.7485110 │ 5.011875653 4.24771
│ workload_32_224_224_uint8 │ 2800 │ 63.789230 │ 5.11 │ 548 │ 1826 │ 378.615982657
│ workload_streaming_request │ 2566000 │ 0.61 │ 6615 │ 4.99514001 │ 2 │ 0.61 │ 1 │ 16
│ workload_streaming_response │ 985000 │ 13.027721 │ 5.0197101 │ 5 │ 0.48 │ 4 │ 7
│ workload_streaming_bidirectional │ 2568000 │ 1.98 │ 25503 │ 4.99514539 │ 2 │ 0.5 │ 1 │ 12
╰──────────────────────────────────┴─────────────────┴─────────────┴──────────┴────────────┴──────────────┴─────────┴──────┴──────╯
╭──────────────────────────────────┬─────────────┬────────────────┬────────────┬──────────────┬─────────┬──────┬──────╮
│ Benchmark │ Avg Memory │ Avg Allocs │ Throughput │ Avg duration │ Std-dev │ Min │ Max │
│ │ KiB/message │ allocs/message │ calls/s │ μs │ μs │ μs │ μs │
├──────────────────────────────────┼─────────────┼────────────────┼────────────┼──────────────┼─────────┼──────┼──────┤
│ workload_smol │ 2.95 72.518424543.544866
│ workload_32_224_224_uint8 │ 637.0 79.1 │ 548 │ 1826 │ 405.4816022730
│ workload_streaming_request │ 0.61 │ 6.6508983 │ 2 │ 0.67 │ 1 │ 15
│ workload_streaming_response │ 12.99 27.6194689 │ 5 │ 0.52 │ 4 │ 9
│ workload_streaming_bidirectional │ 1.98 │ 25.5490718 │ 2 │ 0.59 │ 1 │ 13
╰──────────────────────────────────┴─────────────┴────────────────┴────────────┴──────────────┴─────────┴──────┴──────╯
```

### Real World: `julia -t auto`

Using more threads isn't great for async IO, but this is likely how most people will be using `gRPCClient.jl`.

```
╭──────────────────────────────────┬─────────────────┬─────────────┬──────────┬────────────┬──────────────┬─────────┬──────┬──────╮
│ Benchmark │ N │ Memory │ Allocations │ Duration │ Throughput │ Avg duration │ Std-dev │ Min │ Max │
│ │ calls │ MiB │ │ s │ calls/s │ μs │ μs │ μs │ μs │
├──────────────────────────────────┼─────────────────┼─────────────┼──────────┼────────────┼──────────────┼─────────┼──────┼──────┤
│ workload_smol │ 91000 │ 3.7585123 │ 5.031807955 │ 3.964867
│ workload_32_224_224_uint8 │ 2900 │ 63.789188 │ 5.01579172897.8616141899
│ workload_streaming_request │ 1841000 │ 0.896482 │ 4.99368669 │ 3 │ 1.35 │ 2 │ 21
│ workload_streaming_response │ 330000 │ 13.0 │ 27838 │ 5.026577115 5.2 │ 6 │ 37
│ workload_streaming_bidirectional │ 405000 │ 1.4825672 │ 5.0 80948 128.52362
╰──────────────────────────────────┴─────────────────┴─────────────┴──────────┴────────────┴──────────────┴─────────┴──────┴──────╯
╭──────────────────────────────────┬─────────────┬────────────────┬────────────┬──────────────┬─────────┬──────┬──────╮
│ Benchmark │ Avg Memory │ Avg Allocs │ Throughput │ Avg duration │ Std-dev │ Min │ Max │
│ │ KiB/message │ allocs/message │ calls/s │ μs │ μs │ μs │ μs │
├──────────────────────────────────┼─────────────┼────────────────┼────────────┼──────────────┼─────────┼──────┼──────┤
│ workload_smol │ 2.95 72.51801456 │ 3.085064
│ workload_32_224_224_uint8 │ 637.0 79.7567176299.0716281911
│ workload_streaming_request │ 0.86 6.5341851 │ 3 │ 1.68 │ 2 │ 30
│ workload_streaming_response │ 13.0 │ 27.764515165.12 │ 6 │ 33
│ workload_streaming_bidirectional │ 1.41 25.6102072 106.23452
╰──────────────────────────────────┴─────────────┴────────────────┴────────────┴──────────────┴─────────┴──────┴──────╯
```

## Acknowledgement
Expand Down
20 changes: 10 additions & 10 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ benchmark_table()
```

```
╭──────────────────────────────────┬─────────────────┬─────────────┬──────────┬────────────┬──────────────┬─────────┬──────┬──────╮
│ Benchmark │ N │ Memory │ Allocations │ Duration │ Throughput │ Avg duration │ Std-dev │ Min │ Max │
│ │ calls │ MiB │ │ s │ calls/s │ μs │ μs │ μs │ μs │
├──────────────────────────────────┼─────────────────┼─────────────┼──────────┼────────────┼──────────────┼─────────┼──────┼──────┤
│ workload_smol │ 94000 │ 3.7485110 │ 5.011875653 4.24771
│ workload_32_224_224_uint8 │ 2800 │ 63.789230 │ 5.115481826378.615982657
│ workload_streaming_request │ 2566000 │ 0.616615 │ 4.9951400120.61116
│ workload_streaming_response │ 985000 │ 13.0 │ 27721 │ 5.0197101 5 0.484 7
│ workload_streaming_bidirectional │ 2568000 │ 1.9825503 │ 4.99514539 2 0.5112
╰──────────────────────────────────┴─────────────────┴─────────────┴──────────┴────────────┴──────────────┴─────────┴──────┴──────╯
╭──────────────────────────────────┬─────────────┬────────────────┬────────────┬──────────────┬─────────┬──────┬──────╮
│ Benchmark │ Avg Memory │ Avg Allocs │ Throughput │ Avg duration │ Std-dev │ Min │ Max │
│ │ KiB/message │ allocs/message │ calls/s │ μs │ μs │ μs │ μs │
├──────────────────────────────────┼─────────────┼────────────────┼────────────┼──────────────┼─────────┼──────┼──────┤
│ workload_smol │ 2.95 72.518014563.085064
│ workload_32_224_224_uint8 │ 637.0 79.7567176299.0716281911
│ workload_streaming_request │ 0.86 6.534185131.68230
│ workload_streaming_response │ 13.0 │ 27.7 64515 16 5.12633
│ workload_streaming_bidirectional │ 1.41 25.610207210 6.23452
╰──────────────────────────────────┴─────────────┴────────────────┴────────────┴──────────────┴─────────┴──────┴──────╯
```

### Stress Workloads
Expand Down
24 changes: 11 additions & 13 deletions src/Curl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ end
function grpc_timeout_header_val(timeout::Real)
if round(Int, timeout) == timeout
timeout_secs = round(Int64, timeout)
return "$(timeout_secs)S"
return "$(string(timeout_secs))S"
end
timeout *= 1000
if round(Int, timeout) == timeout
timeout_millisecs = round(Int64, timeout)
return "$(timeout_millisecs)m"
return "$(string(timeout_millisecs))m"
end
timeout *= 1000
if round(Int, timeout) == timeout
timeout_microsecs = round(Int64, timeout)
return "$(timeout_microsecs)u"
return "$(string(timeout_microsecs))u"
end
timeout *= 1000
timeout_nanosecs = round(Int64, timeout)
return "$(timeout_nanosecs)n"
return "$(string(timeout_nanosecs))n"
end

mutable struct gRPCRequest
Expand Down Expand Up @@ -238,22 +238,19 @@ mutable struct gRPCRequest
# Uncomment this for debugging purposes
# curl_easy_setopt(easy_handle, CURLOPT_VERBOSE, UInt32(1))

http_url = replace(url, "grpc://" => "http://")
http_url = replace(http_url, "grpcs://" => "https://")

curl_easy_setopt(easy_handle, CURLOPT_URL, http_url)
curl_easy_setopt(easy_handle, CURLOPT_URL, url)
curl_easy_setopt(easy_handle, CURLOPT_TIMEOUT, deadline)
curl_easy_setopt(easy_handle, CURLOPT_PIPEWAIT, Clong(1))
curl_easy_setopt(easy_handle, CURLOPT_POST, Clong(1))
curl_easy_setopt(easy_handle, CURLOPT_CUSTOMREQUEST, "POST")

if startswith(http_url, "http://")
if startswith(url, "http://")
curl_easy_setopt(
easy_handle,
CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE,
)
elseif startswith(http_url, "https://")
elseif startswith(url, "https://")
curl_easy_setopt(easy_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS)
end

Expand All @@ -275,7 +272,7 @@ mutable struct gRPCRequest
easy_handle,
grpc.multi,
headers,
http_url,
url,
request,
0,
response,
Expand Down Expand Up @@ -797,8 +794,9 @@ function check_multi_info(grpc::gRPCCURL)
# The actual cleanup/notification happens here
cleanup_request(grpc, req)

# Remove from the list of requests associated
grpc.requests = filter(x -> x !== req, grpc.requests)
# Remove from the list of requests associated (in-place, no allocation)
idx = findfirst(x -> x === req, grpc.requests)
!isnothing(idx) && deleteat!(grpc.requests, idx)
else
@error("curl_multi_info_read: unknown message", message, maxlog = 1_000)
end
Expand Down
10 changes: 7 additions & 3 deletions src/gRPC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ end

function url(client::gRPCServiceClient)
protocol = if client.secure
"grpcs"
"https"
else
"grpc"
"http"
end
"$protocol://$(client.host):$(client.port)$(client.path)"

# "$protocol://$(client.host):$(client.port)$(client.path)"
buffer = IOBuffer()
write(buffer, protocol, "://", client.host, ":", string(client.port), client.path)
String(take!(buffer))
end


Expand Down
14 changes: 5 additions & 9 deletions utils/gRPCClientUtils.jl/src/Benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ function perform_benchmark(f, N)

return [
f,
N_sample,
mem,
b.allocs,
round(timing, digits = 2),
1000*mem / N, # Avg Memory
round(b.allocs / N, digits = 1), # Avg Allocs
round(Int, N_sample/timing), # Throughput
round(Int, mean(timings_us) / N), # Avg duration
round(std(timings_us) / N, digits = 2),
Expand All @@ -33,17 +31,15 @@ function benchmark_table()
column_labels = [
[
"Benchmark",
"N",
"Memory",
"Allocations",
"Duration",
"Avg Memory",
"Avg Allocs",
"Throughput",
"Avg duration",
"Std-dev",
"Min",
"Max",
],
["", "calls", "MiB", "", "s", "calls/s", "μs", "μs", "μs", "μs"],
["", "KiB/message", "allocs/message", "calls/s", "μs", "μs", "μs", "μs"],
]
all_benchmarks = [
(workload_smol, 1_000),
Expand Down