56 Commits
Author SHA1 Message Date
Cory Benfield 3cbebafccb Add 5.6 nightly CI (#324)
* Add 5.6 nightly CI

The 5.6 nightly images are available, let's use them.

* Update alloc limits
2022-01-18 02:19:40 -08:00
George Barnett 6e94a7be32 Update nightly allocation limits (#321)
Motivation:

Recent nightly builds have introduced small allocation regressions.

Modifications:

Update allocation limits for nightly Swift builds.

Result:

CI passes.
2021-12-15 10:40:29 +00:00
Cory Benfield b5919e4621 Swift nightly has improved alloc counts. (#314)
This patch updates the alloc counter to enforce the new numbers.
2021-11-25 10:26:32 +00:00
Cory Benfield 326f7f9a8c Simplify the canonicalForm subscript further. (#310)
Motivation:

The canonicalForm subscript was written for clarity, but it didn't do a
good job of avoiding performance costs. Unfortunately, this function can
be a bit costly, for two reasons. Firstly, it used a bunch of eager
collection operations, such that it would allocate intermediate arrays.
Secondly, it computed on the String, rather than the UTF8View backing
that string, in order to perform those collection operations. The result
was that it spent a bit too much time messing about with the headers
than it needed to.

Modifications:

- Define a lazy UTF8 view splitting sequence and use it.
- Change to compute on the UTF8View.

Result:

Better performance in the canonicalForm subscript.
2021-09-29 15:00:31 +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 24acfe2a88 Update to 5.5 release in CI (#301) 2021-09-22 14:47:36 +02:00
Cory Benfield f475cb4c9b Account for improved allocs on nightly (#302) 2021-09-22 13:08:49 +01:00
George Barnett dbe7fb05fe Fix doc generation and jazzy version (#298)
From: https://github.com/apple/swift-nio-extras/pull/141

Motivation:

The combination of Ruby and Jazzy are throwing up issues in CI on older
Ubuntu versions.

Modifications:

- Only install Jazzy on focal
- Fix doc generation script to use more recent source-kitten syntax

Results:

- CI doesn't complain
- Docs get built
2021-09-03 14:38:04 +01:00
David Evans 488444b14c Remove support for Swift 5.0 and 5.1 (#292)
* Update package

* Update CI

* Add to readme
2021-06-23 08:37:07 +01:00
Cory Benfield 798079d137 Update our allocation counter numbers. (#290)
Motivation:

Our 5.5 allocation counts were off. Rather than just update that by hand
we should bring over some tooling to do it automatically.

Modifications:

- Bring over and adapt the update-alloc-limits scripts from NIO.
- Run them and commit the updates.

Result:

CI should pass again.
2021-06-08 16:27:22 +01:00
Johannes Weiss 000f5ee297 add Swift 5.5 job (#287) 2021-05-05 07:40:13 +01:00
Johannes Weiss cec5d4be1f docker setup for main nightlies (#277)
* docker setup for main nightlies

* Update docker-compose.2004.main.yaml
2021-05-04 20:45:37 +01:00
Johannes Weiss b8c1a95661 docker: use 5.4 release instead of nightly (#285) 2021-05-04 19:53:34 +01:00
Johannes Weiss 1292e91814 update latest alloc limits from NIO 2.28.0 release (#286) 2021-05-04 19:17:12 +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
George Barnett 26ddb6e007 Update allocation count requirements (#281)
Motivation:

NIO 2.26.0 saved us some allocations, some of our limits are now too
high and CI fails as a result.

Modifications:

- Adjust the allocation counter limits.
- Replace a 'class' constraint with 'AnyObject'

Result:

CI passes.
2021-03-09 13:50:57 +00:00
Johannes Weiss fa3775a134 Swift 5.4 Docker setup (#275) 2021-02-16 20:01:33 +00:00
Fabian Fett 16e49c6246 Use welcoming language (#274) 2021-01-22 08:55:07 +00:00
George Barnett 0c99c555c5 Avoid unnecessary futures in stream creation (#271)
Motivation:

The stream channel configure function uses a chain of futures where the
same can be achieved in fewer futures.

Modifications:

- Merge the future chains where possible in HTTP2StreamChannel.configure

Result:

A 1.3% reduction in instructions in server_only_10k_requests_1_concurrent
2021-01-14 17:14:17 +00:00
Cory Benfield 59941f6803 Re-add "run all" mode to performance tester (#272)
The run-all mode of the performance tester inadvertently got removed in
a previous patch. This adds it back.

Along the way we have apparently unlocked some perf gains in a new NIO
release.
2021-01-11 17:12:55 +00:00
Cory Benfield 37919ba1b7 Reduce the cost of flushing (#265)
Motivation:

The OutboundFlowControlBuffer is responsible for managing DATA and
HEADERS frames for all streams in order to ensure that we obey HTTP/2
flow control rules, even when users don't. This object is therefore on
the data path for the vast majority of frames, and is extremely
performance sensitive.

Unfortunately, the current algorithm has some nasty performance cliffs.
Right now it has the awkward property of making flushes take an amount
of time linear in the number of streams on the connection, not the
number of streams that had had frames sent on them. The result is that
connections with highly parallel numbers of streams see extremely poor
performance when flushing, a problem that is exacerbated if other parts
of the HTTP/2 stack fail to coalesce those flushes.

We can clean this up in a few ways, but the easiest way is to just keep
track of which streams have done I/O since the last flush. While we're
there, we can make a few other optimisations to ensure we only flush
data on streams we are actually processing, to further reduce the risk
of wasting our time processing unnecessary work.

Modifications:

- Add a Set to keep track of where we've done writes since the last
   flush.
- Streams whose flow control window goes to zero stop being writable.
- Cheaper and more accurate calculation of zero-length writes, which
   avoids the possibility of awkward stalls with zero-length DATA frames
   and END_STREAM.
- Stop doing math about the number of flushed bytes, we don't use that
   information any more.

Results:

An approximately 10% performance gain on the 100 concurrent streams
server-only benchmark. The relative performance gain shifts with the
number of active streams, but it should be positive in all cases.
2020-12-03 11:00:25 +00:00
Cory Benfield c61955a870 Use proper String unsafeUninitializedCapacity initializer. (#263)
Motivation:

A while ago we shimmed out the String unsafeUninitializedCapacity
initializer because while it was on the road to being implemented, it
hadn't actually been implemented. Now it has!

On Apple platforms, the initializer is guarded behind an availability
guard. We need to add that guard here. This means we need to keep hold
of the backport for a good long time, until we raise our minimum Apple
platform support to a new enough version. Happily, Linux on 5.3 should
just see a net win here.

Modifications:

- Updated to enable us to use the proper initializer.

Result:

Fewer allocations when screwing around with HPACK.
2020-11-28 15:56:31 +00:00
Cory Benfield 57976bcc1d Improve bulk stream teardown. (#261)
Motivation:

The logic for doing bulk stream teardown in the ConnectionStreamsState
was always a bit janky: we'd grab all the stream IDs out of the map,
filter out anything that was too small, insert them one-by-one into a
circular buffer, and then report back. I basically just translated that
directly into StreamMap, but on StreamMap this potentially performs very
poorly, as attempting to find the pivot point becomes a linear scan
through the stream data even when there are _loads_ of streams.

This patch swaps over to add a specialized function for bulk-removal of
streams. The specialized function passes the slice of data to be removed
to the caller so that they can compute on it. It does this by a closure
to try to avoid a CoW where possible.

While we're here I tried to address the loop over the CircularBuffer of
recently reset streams. This flushed out an awkward bug that has existed
in our recently reset streams logic for a very long time, which is that
while we _tried_ to maintain the size of the circular buffer, in
practice we misunderstood the CircularBuffer invariants and so this
never worked. I've added a bunch of unit tests for that logic and fixed
it up.

These two changes together will improve performance in stream bulk
teardown. This is an uncommon case (it only happens on GOAWAY), but it's
still good to make that faster.

Modifications:

- New operation on StreamMap
- New prependWithoutExpanding(contentsOf:) operation
- Unit tests for the circular buffer and stream map logic.

Result:

Better performance on bulk stream teardown.
2020-11-26 09:18:46 +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 BenfieldandGeorge Barnett a08dce89a6 Implement StreamMap and replace Dictionary (#258)
Motivation:

When working with HTTP/2 we frequently have a need to store "per-stream"
state. This is state that is independently reproduced once per stream.
We often need to look up this state by stream ID, and so we are
motivated to store this state as efficiently as possible.

Naively, Dictionary seems like a useful data type for this. However,
Dictionaries are not free. The cost of hashing in order to index into a
Dictionary can be substantial. This is both because the hashing function
itself is branchy and complex, but also because the dictionary access is
very unfriendly to the branch predictor and the memory caching systems.

We can take advantage of the fact that if you split streams into client
and server namespaces, stream IDs are strictly ordered. That is, streams
are created in order of increasing stream ID. While streams are
_retired_ out of order, at no point will a CircularBuffer of stream IDs
ever be unordered.

This unlocks a very powerful data structure for us: the ordered "Array"
(in our case actually CircularBuffer). An ordered Array supports two
powerful lookup tools. Firstly, it supports the mighty binary search.
This means the absolute worst-case searching performance for an ordered
Array is log(n) in the size of the Array. Finding a stream by stream ID
in an Array of one million streams would take around 20 steps: extremely
cheap.

For smaller sizes, however, we unlock the one true searching function:
linear scan. On modern CPUs, performing simple computations (such as
checking if one number equals another) is orders of magnitude faster
than looking data up in memory. More importantly, modern CPUs can often
effectively compute multiple lookups at once thanks to their
out-of-order superscalar pipelines. As a result, on any modern CPU
(including all mobile CPUs) a linear search outperforms almost any other
searching algorithm for surprisingly large Array sizes!

Given that stream IDs are intrinsically sorted, and thus all
per-stream-data is intrinsically sorted by stream ID, we have the
ability to use either of the above strategies. More importantly for us,
we have the ability to be _adaptive_ to those strategies, and swap
between them as needed.

Thus we deploy the StreamMap. This data structure stores per-stream data
in a pair of circular buffers, keyed by stream ID. For smallish numbers
of streams we just search these buffers linearly. For larger numbers, we
flip over to binary search.

Why circular buffers? Because we avoid a compaction problem. While in
general removal of stream IDs is done in arbitrary order, in _general_
the mostly likely streams to end at any given time are the oldest and
the youngest. Circular buffers make removing streams at those ends very
cheap, as compaction can be done easily. This, along with avoiding new
allocations, makes circular buffers a perfect data structure for this
strategy.

Modifications:

- Implemented StreamMap
- Replaced Dictionary

Results:

Meaningful performance gains on all benchmarks. 1k requests with 1
concurrent stream sees about a .1% performance improvement. 1k requests
with 100 concurrent streams sees a more like 15% performance
improvement.

Co-authored-by: George Barnett <gbarnett@apple.com>
2020-11-24 12:57:37 +00:00
Cory Benfield 7435b8446f Reduce allocations in OutboundFlowControlBuffer. (#257)
Motivation:

Heap allocations that aren't necessary for program correctness are to be
avoided.

Modifications:

- Avoid heap allocating for constructing indirect enum cases.

Result:

Fewer heap allocations.
Resolves #255.
Reduces instructions executed in cachegrind server-only benchmarks by
about 0.15%.
Reduces icache miss rate by 3% in cachegrind due to reduced jumps to
cold malloc code.
2020-11-19 14:00:15 +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 78ddbdfca1 We now use the main branch. (#250) 2020-09-24 16:26:39 +01: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
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 67226478b9 Swift 5.3-RELEASE is here, let's use it (#238) 2020-09-21 10:19:52 +01:00
Peter AdamsandJohannes Weiss 59e864c1a2 Enable thread sanitizer in CI (#212)
Motivation:

Thread Sanitizer will find bugs which might be missed otherwise.

Modifications:

When running docker image for 1604/5.1 tests and h2spec are both compiled with --sanitize=thread

Result:

Tests are run with thread sanitizer turned on.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-07-23 14:08:48 +01:00
Peter Adams 9feeb176ce Don't install Jazzy on Xenial (#211)
Motivation:

Ruby on Xenial is too old for the cocoapods downloader which jazzy uses.

Modifications:

Change Dockerfile to not install Jazzy on xenial.

Result:

Dockerfile will build again, but bionic or later is required for docs.
2020-07-21 18:03:06 +01:00
tomer doron 1cd4b833b3 improve 5.3 docker setup (#201)
motivation: pin to 5.3 nighties 

changes: use swiftlang/swift:nightly-5.3-master-bionic instead of swiftlang/swift:nightly-master-bionic
2020-05-05 07:04:57 +01:00
Cory Benfield b26b154c4a Fixup the docker setup. (#196) 2020-04-20 19:02:19 +01:00
tomer doron 73be3a1d8b improve docker security (#180)
motivation: more secured ci setup

changes:
* enable :z selinux flag on bind mounts so we can enable selinux on ci
* drop potentially exploitable capabilities from docker-compose
2020-02-01 07:41:23 +00:00
Johannes Weiss 994c319e03 namespace ChannelOptions & fix deprecations (#166) 2019-10-28 16:11:12 +00:00
tomer doron 97e8bbbcf8 api breakage detection (#163)
motivation: test for api breakage on PR

changes:
* add script to detect api breakage
* amend docker setup to include jq
2019-10-07 15:00:10 -07:00
tomer doron 84189320bc swift 5.1 docker setup (#158)
* swift 5.1 docker setup

motivation: support swift 5.1

changes:
* add docker compose file for swift 5.1, will add CI job once merged
* update swiftformat version to 0.40.12
* use more standard dockerfile setup

* 16.04
2019-09-24 21:58:38 +01:00
Johannes Weiss 93f9b98b83 fix allocation counter limits (#148)
Motivation:

We regressed 4 allocations in the security update
https://github.com/apple/swift-nio-http2/security/advisories/GHSA-jchv-x857-q8fq
. Four allocations are a great tradeoff for a number of security
vulnerabilities fixed but we need to raise the limits accordingly.

Modifications:

Raise the limits to the new limit so tests can pass again.

Result:

PRs can pass again and master should build again.
2019-08-13 18:24:46 +01:00
Cory Benfield 492a77b186 Support child channel writability management. (#142)
Motivation:

It's important to ensure that child channel users can observe the
writability state of a child channel in order to avoid ballooning data
in memory. Up until now we haven't supported writability notifications,
but we really should.

Modifications:

- Added a flow controller to manage writability.
- Managed data flow through promises.
- Lots of tests.

Result:

Child channels will provide a much better signal as to whether they are
writable.
2019-07-19 16:49:22 +01:00
tomer doron 3d0b38268e add performance analysis docker-compose setup and script (#141)
motivation: prepare to run performance tests in ci

changes:

add performance-test docker-compose task
add script that can parse the performance test suite results and compare between two result-sets
add generic shell docker-compose task
2019-07-16 11:04:26 +01:00
tomer doron c7c0ca91bf use official docker image (#130)
motivation: now that swift has official docker images, use them instead of the homebrewed one

changes: refactor docker file to use swift:version instead of ubuntu:version
2019-05-21 16:43:48 -07:00
tomer doron e25490e336 improve docker test setup (#129)
motivation: test task to include h2spec

changes:
* remove older docker-compose files that are not in use on the master branch
* move the task definition from the 18.04/5.0 docker compose file to the generic one
* create a unit-test task to encapsulate the unit tests and change the test task to include unit tests, integration tests and h2 spec verification
2019-05-21 09:49:24 +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 8fb84b260a enable warnings as errors (#127)
Motivation:

Warnings are bad, let's make them errors.

Modifications:

enable `-warnings-as-errors`

Result:

Fewer warnings.
2019-05-17 18:15:30 +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
tomer doron 13d9b4852e add doc generation script (#77)
motivation: publish API docs

changes:
* amend docker file to include jazzy
* add doc generation script based on what we have in swift-nio and swift-log
2019-03-27 09:33:19 +00:00
Johannes Weiss a4a1d9c727 use Swift 5.0 release (#74) 2019-03-26 11:20:13 +00:00