34 Commits
Author SHA1 Message Date
Cory Benfield 728149ca4f Update the thresholds for 6.4 (#568) 2026-10-07 11:06:59 +01:00
Aryan Shah d6f5f25943 Rate-limit PING, SETTINGS, PRIORITY, ALTSVC, and ORIGIN frames (#561)
### Motivation

We currently mitigate against receiving an excessive numbers of
RST_STREAM frames, empty DATA frames, or encountering stream errors in a
given time window.

Receiving excessive numbers of PING, SETTINGS, PRIORITY, ALTSVC, or
ORIGIN frames also results in the endpoint performing unnecessary work.
As such, this PR adds these five frames to the current rate-limiting
mechanism.

### Modifications

- Updated `DOSHeuristics` to also rate-limit PING, SETTINGS, PRIORITY,
ALTSVC, and ORIGIN frames.
- Added a new `controlFrameRateLimit` property to
`NIOHTTP2Handler.ConnectionConfiguration`.
- Plumbed the configuration argument to `NIOHTTP2Handler` initializers.

### Result

Mechanism in place to avoid endpoints from being overwhelmed by
excessive PING, SETTINGS, PRIORITY, ALTSVC, or ORIGIN frames.
2026-08-18 17:43:05 +01:00
nishaddeokar 281170341a Fix outbound stream starvation (#559)
Motivation:

`nextStreamToSend()` returned `self.flushableStreams.first`, and since `Set.first` always yields the same stable element, under load the buffer kept handing the whole connection window to one stream while the rest starved to near-zero.

Modifiations:

Rotate through the flushable streams instead of always picking the same one. `flushableStreams` stays the source of truth for membership, and alongside it we keep a queue of those streams (`sendQueue`) in the order to serve them. We pop the front to pick the next stream, and append it to the back once it's been served, so every flushable stream gets a turn per sweep and none can be starved. Both the pop and the append are O(1). Removing a stream from the middle of the queue would be O(n), so we avoid this. A stream that stops being flushable is left as a stale entry and simply skipped when it reaches the front (lazy deletion), with a `queuedStreams` set to stop us ever enqueuing a duplicate.
2026-08-07 08:36:41 +01:00
Rick Newton-RogersandGeorge Barnett 335e5b5b9d Drop Swift 6.0 (#545)
Motivation:

Swift 6.0 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 6.1
* Remove Swift 6.0 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2026-04-07 12:14:31 +00:00
Rick Newton-Rogers ac262c1f36 Enable Swift 6.3 jobs in CI (#544)
Motivation:

Swift 6.3 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.3 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2026-04-01 14:03:11 +01:00
Fabian Fett 979f431f1f Optimize HTTP2ToHTTP1 client codec to reduce empty data frames (#535)
The codec now caches the most recent outbound frame and only writes it
on flush or when receiving `.end`. This lets us set `endStream=true` on
the final data or headers frame instead of sending a separate empty data
frame.

Changes:
- Introduced `PendingFrameWrite` to cache frame payload and promise
- Modified `processOutboundData` to return optional frames instead of
writing immediately
- Added `flush()` method to both client codecs to handle cached writes
- Promise merging ensures correct completion notification when combining
frames
2026-02-10 10:16:27 +00:00
aryan-25 c1bb956720 Update allocation thresholds (#534)
Motivation:

The nightly CI checks for Integration Tests started failing since run
https://github.com/apple/swift-nio-http2/actions/runs/19310336168/job/55228659542
(on 12 November 2025) due to multiple allocation benchmark tests
exceeding their allocation thresholds.

The date these failures started coincides with [release 2.89.0 of
`swift-nio`](https://github.com/apple/swift-nio/releases/tag/2.89.0). In
particular, all failing allocation benchmarks use `EmbeddedChannel`, and
`EmbeddedChannel` was changed in [a PR contained in that
release](https://github.com/apple/swift-nio/pull/3442) that introduced
some changes leading to greater allocations.

[Another change to
`EmbeddedChannel`](https://github.com/apple/swift-nio/pull/3495) in
`swift-nio`'s latest release
([2.94.0](https://github.com/apple/swift-nio/releases)) has also
increased the number of allocations in benchmarks using
`EmbeddedChannel`.

As such, we should update the allocation thresholds for affected tests
accordingly.

Modifications:

Updated the allocation threshold for all affected tests across all
versions.

Result:

Integration tests should no longer fail.
2026-02-09 12:41:37 +00:00
Fabian FettandRick Newton-Rogers c2ba4cfbb8 Drop Swift 5.10, Use Swift 6 language mode (#525)
Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-11-11 14:39:46 +00:00
Rick Newton-Rogers b450646b59 Enable Swift 6.2 jobs in CI (#526)
Motivation:

Swift 6.2 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.2 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2025-09-22 12:42:17 +00:00
Gus Cairo bf0645a009 Update allocation thresholds (#520) 2025-07-03 16:39:55 +01:00
Rick Newton-RogersandGeorge Barnett ee831fb9e7 Drop Swift 5.9 (#515)
Motivation:

Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-05-07 07:59:35 +01:00
Rick Newton-Rogers 31d5bdb86b update thresholds (#513)
update thresholds from Swift 6.0 thresholds
2025-04-14 11:59:58 +01:00
Rick Newton-Rogers dc299eae72 Delete Thresholds/nightly-6.1.json symlink (#497)
Following on from https://github.com/apple/swift-nio-http2/pull/496
delete `Thresholds/nightly-6.1.json` which is no longer needed now that
the shared benchmarks workflow has been updated
2025-03-07 12:09:27 +00:00
Rick Newton-Rogers 41e1821e08 move nightly-next thresholds and add legacy symlink (#496)
Move nightly-next thresholds and add legacy symlink; see
https://github.com/apple/swift-nio/pull/3122
2025-03-03 15:47:09 +00:00
Rick Newton-Rogers 8243b9f525 update benchmark thresholds to nightly 6.1 (#491)
NIO regressed the allocations in EmbeddedChannel by one in
https://github.com/apple/swift-nio/commit/2d72ada99957e8aa19245ccd013f55790be781d9,
This test is regressed by two and uses two embedded channels so it seems
the likely cause.
2025-01-31 09:03:40 +00:00
George Barnett 124e859117 Better handle new streams when server is quiescing (#481)
Motivation:

When the server is in the locally quiescing state and a client attempts
to open a new stream, the connection state machine treats receiving the
headers as a connection error. This results in the connection being
closed and in-flight requests being failed.

This can happen because of the inherent race between the server sending
a GOAWAY frame and the client receiving it, during which time the client
can open a stream not knowing it's doomed to failure.

Rather than the server treating this as a connection error, it should
reject the stream with a RST_STREAM frame and emit a stream error.

Modifications:

- Emit a stream error when receiving HEADERS in the locally quiesced
state

Result:

Better handling of new streams when the server is quiescing
2025-01-20 18:01:49 +00:00
Gus Cairo 170f4ca06b Don't fail closeFuture when an error occurs on closing (#487)
Strictly speaking, a `close` operation can't really fail (except when
the closing mode isn't supported or the channel is already closed). Even
if an error is encountered while closing a channel, or if an error
caused the channel to be closed, the end result is the same: the channel
will be closed.

In this case in particular, when streams are closed from the client
(i.e. by sending a RST_STREAM frame) the `HTTP2StreamChannel` would fail
the channel's `closeFuture`. This isn't appropriate however, as the
channel is successfully closed.

This change stops failing the stream channel's `closeFuture`. Instead,
if the close happens uncleanly, the error will be fired down the
pipeline and the `close` method's promise will be failed.
2024-12-16 15:38:34 +00:00
Peter Adams 4bce87f3cf Enable ShellCheck CI (#478)
Motivation:

Complete enablement of all standard GitHub Actions workflows.

Modifications:

Describe the modifications you've done.

Result:

After your change, what will change.
2024-10-30 15:22:05 +00:00
Peter Adams 70643b7392 Add integration tests to GitHub Actions (#476)
Motivation:

Testing is good - we should check results on PRs.

Modifications:

Add integration tests to PR and scheduled GitHub Actions workflows.

Result:
Integration tests run.
2024-10-30 13:23:03 +00:00
Peter Adams 1118370ec4 Apply swift-format changes and CI (#472)
Motivation:

Standardised formatting makes the project cleaner to look at and work
on.

Modifications:

Setup swift-format with the same settings as Swift-NIO

Result:

Common formatting throughout
2024-10-29 13:09:54 +00:00
Peter Adams bc93af21b0 GitHub Actions to parity with existing CI (#469)
Motivation:

Want to move away from legacy CI.

Modifications:

Add configuration and update code to use GitHub actions.

Result:

GitHub Actions can be used for basic CI.
2024-10-23 14:02:30 +00:00
Gustavo Cairo aab0f121e5 Add alloc tests for alternative stream creation API (#451)
Allocation tests currently use a func that takes a promise to create the stream multiplexer.
However, we also provide a different API that doesn't require a promise and instead returns an `EventLoopFuture<Channel>`.
We don't currently have allocation tests for the latter, so this PR duplicates the current H2 tests but uses the non-promise API to create the multiplexer.
I also had to add a new method on the old H2 multiplexer to conform to a test protocol.
2024-07-16 14:36:38 +01:00
Rick Newton-Rogers bc93efe19a Allocation tests for direct stream multiplexing (#383)
Motivation:

Increase allocation test coverage to encompass new HTTP2Handler direct stream multiplexing.

Modifications:

- Duplicate existing relevant allocation tests
- Introduce a new test for inline and legacy modes which creates multiple streams and then performs many requests on each. This is to give an indication of the performance change through many requests and window update frames.

Result:

More allocation test coverage.
2023-04-06 07:46:49 +01:00
George Barnett 80f02ef18a Add perf and alloc tests for getting headers (#303)
Motivation:

To justify performance changes we need to measure the code being
changed. We believe that `HPACKHeaders.subscript(canonicalForm:)` is a
little slow.

Modifications:

- Add allocation and performance tests for fetching header values in
  their canonical form

Results:

More benchmarks.
2021-09-27 12:43:35 +01:00
Cory Benfield dbfc8fcd1a Clean up imports and dependencies. (#300)
Motivation:

With NIO 2.32.0 we broke the core NIO module up into modules that split
apart the POSIX layer and the core abstractions. As a result, this
package no longer needs to express a hard dependency on the POSIX layer.

Modifications:

- Rewrote imports of NIO to NIOCore.
- Added NIOEmbedded imports where necessary in tests.
- Note that the main modules still depend on NIO, which is necessary
    for backwards-compatibility reasons. This dependency is unused.

Result:

No need to use NIOPosix.
2021-09-14 11:30:04 +01:00
George Barnett e3e9024a63 Stop using deprecated API in allocation counting tests (#284)
Motivation:

Some of the allocation counting tests used frame-based stream channels
rather than the frame payload based ones. These were deprecated some
time ago.

Modifications:

- Update test handlers to be `HTTP2Frame.FramePayload` based
- Update the 'create_client_stream_channel' test to count streams rather
  than summing their stream ID (as stream IDs aren't assigned until the
  stream channel delivers pending writes for the first time).
- Update allocation limits

Result:

Allocation counting tests don't use deprecated APIs.
2021-03-16 14:45:34 +00:00
George Barnett e7af0132c8 Use sync options when creating a stream channel (#283)
Motivation:

SwiftNIO 2.27.0 added synchronous channel options. We can use these if
available when creating a stream channel to avoid a future allocation.

Modifications:

- 'getAutoReadFromParent' is synchronous when possible and now takes a
  closure to handle the result.
- Update allocation counts (and sort them to make updating them easier,
  this also includes switching the order we run test_1k_requests
  interleaved and noninterleaved)

Result:

Fewer allocations.
2021-03-16 10:10:00 +00:00
Cory Benfield 3315a639de Add benchmark and alloc test for GOAWAY teardown. (#260)
Motivation:

We don't have any benchmarks or alloc counter tests for doing stream
teardown with GOAWAY frames. While this isn't a terribly hot code path
and isn't terribly performance heavy with allocations, it's good to have
more data here.

Modifications:

- Write benchmarks and alloc counter tests that tear down many streams
  with GOAWAY.

Result:

Better testing and alloc counter.
2020-11-24 17:24:42 +00:00
Cory Benfield 54f15a6b16 Add benchmarks and improve benchmarking. (#256)
Motivation:

Performance benchmarking wants accurate numbers, and a wide range of
possible benchmarks. One way to get somewhat more accurate numbers is to
use a tool like Cachegrind to measure the instruction counts of a
program. Cachegrind allows us to isolate a number of noise-introducing
effects, as "number of executed instructions" is a much more stable
number than how long a program takes to run.

When running under cachegrind we want to change the way our performance
benchmarks work. Instead of running lots of times to try to average out
noise, we only want to run once to save ourselves time, as the benchmark
itself should be drastically more stable.

While we're here, let's add some much more isolated benchmarks than our
current "make lots of streams" benchmark. This is basically the same
logic, but it does less of NIO and so makes the impact of NIOHTTP2
substantially more prominent.

Modifications:

- Added a cachegrind build mode to the benchmarks.
- Added new benchmarks and alloc counters.

Result:

More info
2020-11-19 11:09:09 +00:00
Cory Benfield 28d94c489d Update alloc counter scaffolding. (#249)
Motivation:

I have suspicions that the allocation counter tests in NIOHTTP2 don't
fail properly, so let's bring the scaffolding up to date.

Modifications:

Update the few local files to the most recent NIO versions.

Result:

Smaller diffs to NIO, maybe better infrastructure?
2020-09-24 13:34:21 +01:00
George Barnett 119ae07fbf Use the non-deprecated 'configureHTTP2Pipeline' in benchmarks (#248)
Motivation:

CI is spitting out a bunch of warnings about 'configureHTTP2Pipeline'
being deprecated; it is called without providing the inbound stream state
initializer. The non-deprecated version requires that this is
explicitly passed as `nil`.

Modifications:

- Explicitly set the 'inboundStreamInitializer' to `nil`

Result:

Fewer warnings.
2020-09-24 10:44:58 +01:00
Cory Benfield 5b0194aa63 Reduce allocations when peeking pseudo-headers. (#246)
Motivation:

The 2 to 1 codecs do a number of operations where they "peek" the
pseudo-headers. Each of these operations uses the HPACKHeaders
subscript, meaning that they allocate a temporary array for a field that
can, in a correct request/response, contain only one element. That's
very wasteful!

Modifications:

- Rewrite peekPseudoHeader to iterate instead, avoiding the array.
- Add allocaton counter test.

Result:

4 fewer allocations per HTTP request transformed on the server side,
2 fewer allocations per HTTP response transformed on the client side.
2020-09-24 09:57:47 +01:00
Cory Benfield 2d5ab32f23 Remove indirection between channel and multiplexer (#126)
Motivation:

Previously the HTTP2StreamChannel forwarded all frames to the parent
Channel by way of the abstract Channel existential API. While this was
straightforward, it added unnecessary overhead due to the extra pipeline
steps and the extra indirection of the types providing an inlining
barrier.

Given that in #116 we gave the HTTP2StreamChannel a reference to its
parent multiplexer, we may as well take advantage of this and allow
direct calls from the stream channel into the multiplexer.

Modifications:

Avoided calls to parent.write and parent.flush.
Replaced them with a new interface.
Added new allocation test for this path.

Result:

Slightly better performance.
2019-05-17 18:58:08 +01:00
Johannes Weiss 16fae8a3d1 add the first allocation tests for nio-http2 (#122)
Motivation:

Allocation tests are good :).

Modifications:

Add two allocations tests and NIO's integration test framework.

Result:

Hopefully fewer allocations in the future. And better ways to check what
allocations are happening.
2019-05-17 14:36:46 +01:00