Commit Graph
190 Commits
Author SHA1 Message Date
Si Beaumont 55d4c49334 Better align shutdown semantics of testing event loops (#2800)
### Motivation:

The two testing event loops—`EmbeddedEventLoop` and `NIOAsyncTestingEventLoop`—have different semantics for outstanding work during shutdown, which are both different from the production `SelectableEventLoop`, specifically with newly scheduled tasks that result from running existing scheduled work at the time of shutdown.

There are three axes to consider:

1. Scheduled tasks that are at or past their deadline.
2. Scheduled tasks with a deadline in the future.
3. Newly scheduled work that result from either running or cancelling (1) and (2).

| | (1) | (2) | (3) |
|-|-|-|-|
| `SelectableEventLoop` | Run | Cancel | Quiesce over 1000 ticks, repeatedly run resulting (1) and cancel resulting (2) |
| `EmbeddedEventLoop` | Run | Cancel | Cancel resulting (1) and resulting (2) |
| `NIOAsyncTestingEventLoop` | Run | Run | Run resulting (1) and resulting (2) |

Note that `NIOAsyncTestingEventLoop` may never terminate because of this.

### Modifications:

This PR aligns `EmbeddedEventLoop` and `NIOTestingEventLoop` and makes them more similar to `SelectableEventLoop` and less surprising semantics.

### Result:

| | (1) | (2) | (3) |
|-|-|-|-|
| `SelectableEventLoop` | Run | Cancel | Quiesce over 1000 ticks, repeatedly run resulting (1) and cancel resulting (2) |
| `EmbeddedEventLoop` | Run | Cancel | Cancel resulting (1) and resulting (2) |
| `NIOAsyncTestingEventLoop` | Run | Cancel | Cancel resulting (1) and resulting (2) |

### Future work:

Given both the `EmbeddedEventLoop` and `NIOAsyncTestingEventLoop` are used in tests of NIO applications that run with `SelectableEventLoop` in production, it might be worth extending both to also support quiescing to give a more representative shutdown behaviour in tests.
2024-07-25 14:38:36 +00:00
Franz Busch 8a69bd9d88 [GHA] Cxx interoperability compatibility and integration tests check (#2790)
# Motivation

Another reusable check is to make sure that all library products of a package are successfully building when consumed from a module that has Cxx interoperability enabled. Another check that's missing is running the integration tests.

# Modification

This PR adds two new checks to the reusable workflow. One to check for Cxx interoperability compatibility and another one to run the integration tests. I also fixed a misalgined name for the nightly benchmarks.

# Result

This should be one of the last reusable workflow checks.
2024-07-16 01:22:04 -07:00
Franz Busch 7b03cb247b Fix benchmark thresholds update script (#2783)
# Motivation

We added new CI to run both nightly main and nightly next but forgot to update the benchmark thresholds script

# Modification

This PR updates the benchmark thresholds script and adds a nightly next docker compose image.

# Result

We can use the update benchmark thresholds script again.
2024-07-13 02:51:05 -07:00
George Barnett 9b86559506 Pre-box some errors to reduce allocations (#2765)
Motivation:

Existential errors (`any Error`) are unconditionally boxed. In NIO we
often create errors to fail promises. One place we do this is in the
head channel handler when the pipeline is closed. This error is created
regardless of whether there are actually any promises to fail. The
result is an unnecessary allocation when every channel is closed. This
is particuarly egregious when multiplexed protocols such as HTTP/2 are
used.

As the majority of errors in NIO carry no information beyond their
type/name we can declare these statically and pay the cost of each error
just once rather than once per use.

Modifications:

- Add internal static constants for `ChannelError` and `EventLoopError`
  and use them throughout NIOCore and NIOPosix where they would
  otherwise be boxed.

Result:

Fewer allocations
2024-07-05 08:01:29 -07:00
Peter Adams 6753556a85 Add slack to rst allocation tests (#2722)
Motivation:

Allocation tests are slightly fragile to small changes.

Modifications:

Allow 50 extra allocations over the 1000 cycles.

Result:

Rst tests less flaky
2024-05-14 07:42:01 -07:00
Peter Adams a5cb713246 No longer need test discovery command line. (#2717)
Motivation:

Command line argument has not been needed for several swift version.

Modifications:

This causes warnings in recent swift versions.

Result:

No more warnings about swift command line when testing
2024-05-07 16:46:41 +01:00
George Barnett cc158ec6c7 Raise minimum Swift version to 5.8 (#2675) 2024-03-11 08:47:57 +00:00
Gregor Milos (Grzegorz Miłoś) 5e470773ca Track execute() and enqueue() tasks separately from scheduled tasks. (#2645) 2024-03-05 16:01:47 +00:00
Franz BuschandCory Benfield 63e8c4e1aa Migrate to syncOperations in more places (#2661)
# Motivation

Adding a handler via the regular `pipeline.addHandler` APIs can lead to transferring the handler over isolation regions. To avoid running into `Sendable` warnings here we can use the `syncOperations` of the pipeline to avoid transferring the handlers.

# Modification

This PR is mostly changing code to avoid transferring handlers to and from the event loops in tests. This should be a no-op mostly.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-03-01 15:05:22 +00:00
Gregor Milos (Grzegorz Miłoś) c3b6f1f3f5 Fix CoW performance bug in NIOThreadPool work queue (#2669)
* Benchmark for measuring NIOThreadPool dispatch

* Avoid CoW cost for NIOThreadPool work queue

* Flip stray `var` to a `let`.

* Use .modifying state to prevent CoW, not a class

* Removing some obselete comment noise.

* Use Deque instead of CirclarBuffer in NIOThreadPool

* Ratchet down the # of allocs for read_10000_chunks_from_file. NIOTheadPool changes reduced the allocations required.
2024-02-28 15:43:52 +00:00
George Barnett cfd51e06f5 Remove large temp file after FS tests (#2658)
* Remove large temp file after FS tests

Motivation:

One of the file system tests copies a large file but didn't clear up
after itself.

Modifications:

- Remove the files after the test

Result:

Less disk space used

* remove tmp
2024-02-19 14:42:55 +00:00
Franz Busch e4102aecb5 Remove @unchecked Sendable conformance from ChannelOptions.Storage (#2638)
# Motivation
We currently have an unchecked `Sendable` conformance on `ChannelOptions.Storage` which is not necessary and in fact we are missing a proper `Sendable` requirement on the `ChannelOption.Value` protocol right now.

# Modification
This PR adds the `Sendable` requirement on the `ChannelOption.Value` and replaces the unchecked conformance on the storage with a regular one.

# Result
No more `Sendable` warnings in strict concurrency mode inside `ChannelOptions`.
2024-02-12 09:48:54 +00:00
1445dcabeb Add cxx interop build pipeline (#2614)
* Add cxx interop build pipeline

* Add imports to source

* Update docker-compose for 5.9 and 5.10

* Remove test target

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: David Nadoba <d_nadoba@apple.com>
2023-12-22 02:47:32 -08:00
David Nadoba 23e995b3af Set SWIFT_VERSION environment variable to resolve to the correct benchmarks thresholds path (#2613)
* Set `SWIFT_VERSION` environment variable to resolve to the correct benchmarks thresholds path

* mallocs have increased

* update benchmark results manually

* update thresholds again

* disable flaky benchmark
2023-12-22 11:07:35 +01:00
Adam FowlerandGeorge Barnett e69354f123 Async apis for NonBlockingFileIO (#2576)
* Async versions of NonBlockingFileIO functions

I have not produced async versions of the readChunked functions. These
would likely be replaced with an AsyncSequence though.

* Add tests for async versions of NonBlockingFileIO

* Add wrapper for FileRegion to avoid Sendable issues

* Allocate ByteBuffer in readSync

* Update read_10000_chunks_from_file alloc count

* Add UnsafeTransfer to NIOPosix.

Use in NonBlockingFileIO.openFile functions

* Update Sources/NIOPosix/NonBlockingFileIO.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* formatting, docc

* update comment

* replace openFile with withOpenFile

* More indentation

* Update comments

* Remove docc links to NIOCore types

* Fix read docc links

* Catch errors when closing file handle in withOpenFile

* rename to withFileHandle

* Fix double close on error

Also
- move @available above each function
- Remove wording about separate from Task pool

* Update Sources/NIOPosix/NonBlockingFileIO.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* withOpenFile is now withFileRegion

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2023-11-16 16:21:21 +00:00
Franz Busch d782de84df Adopt package-benchmark (#2534)
# Motivation
We want to migrate our allocation and later on also our performance tests to use the `package-benchmark` plugin. This plugin makes writing benchmarks way easier than our current setup. Furthermore, debugging benchmarks is also possible from within Xcode now.

# Modification
This PR adds the setup for the benchmarking infrastructure and connects it with out

# Result
Allocations tests are more accessible and easier to iterate.
2023-10-08 13:31:22 -07:00
Rick Newton-Rogers 67553a7d6d Bump minimum Swift version to 5.7 (#2524)
* Bump minimum Swift version to 5.7

Motivation:

Now that Swift 5.9 is GM we should update the supported versions and
remove 5.6

Modifications:

* Update `Package.swift`
* Remove `#if swift(>=5.7)` guards
* Delete the 5.6 docker compose file and make a 5.10 one
* Update integration test script
* Update docs

Result:

Remove support for Swift 5.6, add 5.10

* fix indentation issues

* 5.9 docker image use release image
2023-10-02 11:38:07 +01:00
Cory Benfield 27954605cb Update nightly allocation limits (#2502)
The nightly allocation count got better, so we can
update the limits to account for it.
2023-08-15 02:11:27 -07:00
Franz Busch 4c6083f6a3 Fix 5.9 and nightly allocation limits (#2485) (#2487)
# Motivation
Our 5.9 and nightly CI has been failing for some time now due to flaky allocation tests.

# Modification
This PR slightly changes some shared infra for how we ran some of our allocation tests. We are now waiting for the client and server channel to close so that allocations are more stable.

# Results
Green CI again
2023-07-31 09:30:37 +01:00
Franz Busch e77a948e57 Fix 5.9 and nightly allocation limits (#2485)
# Motivation
Our 5.9 and nightly CI has been failing for some time now due to flaky allocation tests.

# Modification
This PR slightly changes some shared infra for how we ran some of our allocation tests. We are now waiting for the client and server channel to close so that allocations are more stable.

# Results
Green CI again
2023-07-28 11:01:47 -07:00
Cory Benfield 60c54a77de Allocations regressed in 5.9 (#2456)
Motivation:

I'm not yet sure why they regressed, but having the CI repeatedly
fail because of this isn't helpful. We should investigate the
regression.

Modifications:

Raise the allocation limits.

Result:

CI is green again.
2023-06-30 03:44:54 -07:00
Franz Busch 8e801f12ff Align ServerBootstrap bind methods with the initializer style (#2443)
* Align ServerBootstrap bind methods with the initializer style

# Motivation

After experimenting with the bind/connect APIs of the other bootstraps, we realized that passing the type of the handler is not working very well and choose to add an initializer closure to all the bind/connect methods which returns a concrete result.

# Modification

This PR aligns the `ServerBootstrap` APIs with the new initializer based approach. To make this work I had to refactor the `NIOAsyncChannel` SPIs a bit. Overall, this is a net reduction in code.

# Result

We now have aligned bootstrap APIs.

* Code review

* Fix CI
2023-06-22 17:43:32 +01:00
Franz Busch 0cdbb1fb38 Add NIOAsyncChannel based connect and bind methods to DatagramBootstrap (#2439)
* Add NIOAsyncChannel based connect and bind methods to DatagramBootstrap

# Motivation
In my previous PR, I added new `connect` methods to `ClientBootstrap` that vend `NIOAsyncChannel` or support an async protocol negotiation. This PR focuses on adding new `connect` and `bind` methods to `DatagramBootstraps` which offer the same functionality.

# Modification
This PR adds new `connect` and `bind` methods that either vend a `NIOAsyncChannel` or an asynchronous protocol negotiation result.

# Result
We can now bootstrap UDP channels with `NIOAsyncChannel`s

* Code review

* Add self

* Remove so_reuseaddr

* Add sleep between client and server bootstrap
2023-06-19 11:10:21 -07:00
Franz Busch b22575ac96 Fix flaky test in NIOAsyncWriter (#2431)
* Fix flaky test in NIOAsyncWriter

# Motivation
We had flaky test in the writer where we were relying on some timing.

# Modification
Change the test so that it is deterministic.

# Result
Fixes https://github.com/apple/swift-nio/issues/2427

* Update allocation counters
2023-05-31 09:53:54 +01:00
Felix Schlegel 47b6289d93 Embedded: getOption(ChannelOptions.allowRemoteHalfClosure) should not fatalError (#2429)
* Embedded: getOption(.allowRemoteHalfClosure) -> OK

Motivation:

In `swift-nio-ssl`, I am currently working on allowing half-closures
which relies on querying the underlying channel if
`ChannelOptions.Types.AllowRemoteHalfClosureOption` is enabled. As a lot of
`swift-nio-ssl`'s tests rely on `EmbeddedChannel` and it did not support
this option, a lot of the tests failed.

Modifications:

* add a `public var allowRemoteHalfClosure` to `EmbeddedChannel`
* enable setting/getting
  `ChannelOptions.Types.AllowRemoteHalfClosureOption` in
`EmbeddedChannel` (only modifies the `allowRemoteHalfClosure` variable
* add test for new behaviour

* AsyncTestingChannel: getOption(.allowRemoteHalfClosure) -> OK

Motivation:

`AsyncTestingChannel` interface should be in step with `EmbeddedChannel`
interface. Therefore also add support for the
`AllowRemoteHalfClosureOption`

Modifications:

* add a `public var allowRemoteHalfClosure` to `AsyncTestingChannel`
* enable setting/getting
  `ChannelOptions.Types.AllowRemoteHalfClosureOption` in `AsyncTestingChannel`
  (only modifies the `allowRemoteHalfClosure` variable
* add tests for new behaviour

* Synchronize access to allowRemoteHalfClosure

Modifications:

* add `ManagedAtomic` property `_allowRemoteHalfClosure` to
  `EmbeddedChannelCore`
* make sure that access to `allowRemoteHalfClosure` from
  `AsyncTestingChannel` and `EmbeddedChannel` is synchronized by
  accessing underlying atomic value in `channelcore`

* Update allocation limits
2023-05-19 09:47:47 -07:00
Johannes Weiss 7a0ec436a1 include relevant versions (kernel & Swift) in test output (#2425) 2023-05-16 02:55:18 -07:00
David Nadoba 6720612111 Drop Swift 5.5 (#2406)
* Drop Swift 5.5

* Use `swift-atomics` 1.1.0 with `Sendable` adoption
2023-04-17 08:40:35 +01:00
Yim LeeandCory Benfield b4ebd5a64a Add docker-compose file for Swift 5.9 (#2404)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-13 12:41:45 +01:00
Cory BenfieldandGeorge Barnett a7c36a7654 Clean up and regression check the docs. (#2400)
Motivation:

Up until recently, it has not been possible to regression check our
documentation. However, in recent releases of the DocC plugin it has
become possible to make warnings into errors, making it possible for us
to CI our docs.

This patch adds support for doing that, and also cleans up our
documentation so that it successfully passes the check.

Along the way I accidentally wrote an `index.md` for `NIOCore` so I
figure we may as well keep it.

Modifications:

- Structure the documentation for NIOCore
- Fix up DocC issues
- Add `check-docs.sh` script to check the docs cleanly build
- Wire things up to our docker-compose scripts.

Result:

We can CI our docs.

Co-authored-by: George Barnett <gbarnett@apple.com>
2023-04-11 09:05:22 +01:00
George Barnett 4dfae01cc6 Add a pooled recv buffer allocator (#2362)
Motivation:

Channels can read `ChannelOptions.maxMessagesPerRead` times from a
socket in each read cycle. They typically re-use the same buffer for
each read and rely on it CoWing if necessary. If we read more than once
in a cycle then we may CoW the buffer. Instead of reusing one buffer we
can reuse a pool of buffers limited by `maxMessagesPerRead` and cycle
through each, reducing the chance of CoWing the buffers.

Modifications:

- Extend `RecvByteBufferAllocator` to provide the size of the next
  buffer with a default implementation returning `nil`.
- Add an recv buffer pool which lazily grows up to a fixed size and
  attempts to reuse buffers where possible if doing so avoids CoWing.

Results:

Fewer allocations
2023-02-20 17:00:19 +00:00
David Nadoba 3d18e94683 Add Swift 5.8 CI and update nightly CI to Ubuntu 22.04 (#2350)
* Add Swift 5.8 CI

* Update nightly CI to Ubuntu 22.04

* Allow slight allocation variance in `1000_udpconnections` test
2023-01-18 10:17:12 +00:00
Philip Brown 59e1f6f375 Tail allocate mutex and a generic value using ManagedBuffer (#2349)
Motivation:

Currently, NIOLock and NIOLockedValueBox incur unnecessary allocation and indirection costs.

Modifications:

Create namespace LockOperations for organization
Create LockStorage<Value>, a subclass of ManagedBuffer<LockPrimitive, Value>
Store the mutex as the header and the generic value as the first and only element
Update NIOLock and NIOLockedValueBox to use LockStorage

Result:

Optimal lock and value memory layout
Fewer allocations and less indirection
Code generation is excellent
2023-01-17 16:11:10 +00:00
David Nadoba 1ce136b4c3 Fix main nightly CI (#2337)
* Fix nightly CI

* conditionalization of signal for architecture
2023-01-09 18:34:48 +00:00
Cory Benfield 0760383b38 Measure allocations applying WS mask (#2333)
Motivation:

We're missing some alloc tests on the WS mask.

Modifications:

- Add extra alloc tests for the WS mask

Result:

We'll have more tests
2022-12-13 18:05:27 +00:00
Franz BuschandCory Benfield 1abe64c5e6 Add benchmarks for NIOAsyncWriter and NIOAsyncSequenceProducer (#2301)
# Motivation
We landed the async bridge types a while back but never added allocation and performance tests. Since we expect these types to be used performance critical paths we really should cover those with tests.

# Modification
Extends the allocation counter scaffolding to support async tests. Furthermore, add allocations tests for both the writer and producer. Lastly, I a also added a performance test for the producer.

# Result
We now have baseline tests for the `NIOAsyncWriter` and `NIOAsyncSequenceProducer`

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-10-26 03:51:20 -07:00
George Barnett fcca969463 Raise minimum supported Swift version from 5.4 to 5.5 (#2267)
Motivation:

SwiftNIO periodically drops support for older Swift versions. Now that
5.7 has been released, 5.4 will be dropped.

Modifications:

- Remove 5.4 specific Package.swift and docker-compose
- Update the 5.7 docker-compose to use the released 5.7 and move from
  focal (2004) to jammy (2204)
- Remove unused swiftformat from Dockerfile
- Update tools version in syscall wrapper tests to 5.5
- Update docs

Results:

Minimum Swift version is 5.5
2022-09-29 11:47:44 +01:00
George Barnett 39e61f636f Update allocation limits (#2272)
Motivation:

a16e2f54a2 allocates more in some cases
because of an additional channel handler.

Modifications:

- Update alloc limits

Result:

CI passes.
2022-09-29 10:10:16 +01:00
Cory Benfield 6918034260 Update HTTP parser to LLHTTP (#2263)
Motivation:

The node.js HTTP parser library that we use has been unmaintained for some time. We should move to the maintained replacement, which is llhttp. This patch will update our dependency and bring us over to the new library, as well as make any changes we need.

Modifications:

This patch comes in 4 parts, each contained in a separate commit in the PR.

The first commit drops the existing http_parser code and updates some of the repo state for using llhttp.
The second commit rewrites the update script to bring in llhttp instead of http_parser.
The third runs the actual script. You can skip reviewing this except to sanity check the outcome.
The fourth commit updates the NIO code and the tests to get everything working.

In general the substance of the product modifications was minimal. The logic around keeping track of where we are in the buffer and how upgrades work has changed a bit, so that required some fiddling. I also had to add an error reporting path for the delegates to be able to throw specific errors that llhttp no longer checks for. Finally, I removed two tests that were a little overzealous and that llhttp does not police.

Result:

Back on the supported path.
2022-09-13 14:09:57 +01:00
Cory Benfield 901e9692b9 Validate missing imports in CI (#2245) 2022-08-15 10:26:34 -07:00
Cory Benfield f5448fbbc2 Provide NIOAsyncTestingChannel (#2238)
Motivation

Testing versions of NIO code that involve interfacing with Swift
Concurrency is currently a difficult business. In particular,
EmbeddedChannel is not available in Swift concurrency, making it
difficult to write tests where you fully control the I/O.

To that end, we should provide a variation of EmbeddedChannel that makes
testing these things possible.

Modifications

Provide an implementation of NIOAsyncTestingChannel.

Results

Users can write tests confidently with async/await.
2022-08-10 11:09:56 +01:00
tomer doronandCory Benfield 712e207f26 initial adoption of DocC based documentaiton (#2235)
* initial adoption of DocC based documentaiton

motivation: use DocC for docs

change:
* add DocC catalog to NIO target, as the "landing page"
* remove jazzy doc generation script
* add Package.swift with tools-version 5.6 so that DocC can be used, and add a dependency on the DocC plugin
* udpate soundness script

* * add packge.swift files for older vrsions
* adjust waning-as-error and enable-test-discovery to the different permutations

* fixup

* remove jazzy

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-08-08 03:55:18 -07:00
Cory Benfield 7fbaed6f4a Use correct alloc limits for 5.7 (#2193) 2022-06-14 11:57:26 +01:00
Cory Benfield ec4072c925 Use 5.7 nightlies (#2186) 2022-06-13 03:06:35 -07:00
David Nadoba 0e2818bf86 Remove @preconcurrency from internal EventLoopFuture methods (#2135)
* add @preconcurrency again as it otherwise results in one more allcation in 1000_udpconnections
2022-06-07 07:09:44 -07:00
David Nadoba 391ab9122c Reduce the alloc limits for main (#2118)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-16 09:56:45 -07:00
David Nadoba 14ffe73e1b Reduce the alloc limits of 1000_tcpconnections for main (#2116)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-16 02:48:31 -07:00
Cory Benfield b1b44ca67b Reduce the alloc limits for main (#2095)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-04 15:49:40 +01:00
Fabian FettandCory Benfield dc8a317a24 Drop support for Swift 5.2 and 5.3 (#2080)
* Drop support for 5.2 and 5.3

As outlined in a [Swift forums post in November ’21](https://forums.swift.org/t/swiftnio-swift-version-support/53232), SwiftNIO will only support the latest non-patch Swift release and the 2 immediately prior non-patch versions.

In this commit we drop support for Swift 5.2 and 5.3. We update CI for Swift 5.4 to run on bionic instead of focal to ensure that we still test bionic.

* Added Versions paragraph to Security document

* Apply suggestions from code review

Co-authored-by: Cory Benfield <lukasa@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-04-20 11:48:41 +01:00
Cory Benfield dde891c624 Update alloc limits for nightly. (#2071)
We regressed allocs in nightly, probably for a Swift bug. Fixing it is
tracked in #2070, for now we're going to raise the limits so CI isn't
moaning all the time.
2022-03-23 10:05:11 -07:00
tomer doron aa631d3c8c ci update (#2066)
motivation: 5.6 is out

changes:
* use release version of 5.6
* add docker setup for 5.7 (using nightly for now)
2022-03-16 21:28:58 -07:00