97 Commits
Author SHA1 Message Date
Cory Benfield e7880565aa We use main as our development branch now. (#1651) 2020-09-24 18:02:44 +01:00
Cory Benfield 06554fd48e Swift 5.3-RELEASE is out, let's use it. (#1631) 2020-09-21 12:09:47 +01:00
Peter Adams 3cfb3f1d6e Don't install Jazzy on Xenial (#1597)
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 17:52:23 +01:00
Peter Adams 8a865bd15e Make UDP connection allocation test more like best practice code. (#1583)
Motivation:

There is at least a theoretical race to flush before close in prior version.
Having terrible code in the NIO repo is asking for someone to copy it.

Modifications:

flatMap the various parts of the client together which also ensures the
flush is complete before close is called.

Result:

Slightly nicer code, slightly fewer allocations.
2020-06-30 17:11:05 +01:00
Peter Adams a035a1b154 UDP allocation tests should not use so_reuseaddr (#1581)
Motivation:

so_reuseaddr on linux allows multiple binding to the same port simultaneously - this has not been seen to happen in practice but it is best to be cautious.

Modifications:

Remove address reuse from the UDP allocation tests.

Result:

Reduced danger of binding the same port twice.
2020-06-29 16:51:42 +01:00
669a19cb7b Set SO_LINGER in integration tests. (#1549)
Motivation:

We now have sufficiently many integration tests that the number of TCP
sockets in TIME_WAIT begins to cause resource pressure on the system.
This can lead to the integration tests failing due to being unable to
assign a socket.

We can force this to not happen by disabling linger. As we're running on
a lossless fabric (localhost), this is entirely safe.

Modifications:

- Disable TIME_WAIT for integration tests.

Result:

Integration tests will pass.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Co-authored-by: Peter Adams <pp_adams@apple.com>
2020-06-24 14:28:40 +01:00
Johannes Weiss 01e0e0cef4 stablise 1000 TCP connections alloc test (#1566)
Motivation:

The 1000 TCP connections allocation counter test did way too many thread
crosses and other things that allocated for unrelated reasons.

Modifications:

Remove those.

Result:

Much more stable
2020-06-23 13:11:43 +01:00
Peter Adams c03dd9c5f1 Make allocation tests produce more stable results (#1565)
Motivation:

Allocation tests are very hard to use productively if they don't produce stable results.

Modifications:

Change TCP and UDP connection tests to monitor on the server side as well as the client side to make sure all data is completely send and received before stopping counting allocations.

Result:

Allocation tests are more stable than before.
2020-06-23 10:25:36 +01:00
Johannes WeissandCory Benfield e57122bd89 ByteBuffer: add convenience initialisers (#1533)
Motivation:

There are multiple sub-optimal ByteBuffer creation patterns that occur
in the wild. Most often they happen when people don't actually have
access to a `Channel` just want to "convert" a `String` into a
`ByteBuffer`. To do this, they are forced to type

    var buffer = ByteBufferAllocator().buffer(capacity: string.utf8.count)
    buffer.writeString(string)

Sometimes, they don't get the capacity calculation right or just put a
`0`.

Similar problems happen if NIO users want to cache a ByteBuffer in their
`ChannelHandler`. You will then find this code:

```swift
if self.buffer == nil {
    self.buffer = receivedBuffer
} else {
    var receivedBuffer = receivedBuffer
    self.buffer!.writeBuffer(&receivedBuffer)
}
```

And lastly, sometimes people want to append one `ByteBuffer` to another
without mutating the appendee. That's also cumbersome because we only
support a mutable version of `writeBuffer`.

Modifications:

- add `ByteBuffer` convenience initialisers
- add convenience `writeBuffer` methods to `Optional<ByteBuffer>`
- add `writeBufferImmutable` which doesn't mutate the appendee.

Result:

More convenience.

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

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-06-04 21:02:11 +01:00
Peter Adams 1d134ccdcc Fine grained UDP allocation tests (#1534)
Fine grained UDP allocation tests

Motivation:

The existing UDP allocation tests count allocations everywhere.

Split out 3 tests to cover:

Making connections.
Making bootstraps.
Transferring data.
Modifications:

Three new tests.

Result:

Easier to debug changes to allocation profiles in UDP.
2020-05-29 12:49:34 +01:00
Peter Adams 51370e4113 Finer grained allocation tests (#1531)
Motivation:

The existing tcp allocation tests cover everything from bootstrap creation through to sending data in one massive test. The parameters of how many iterations control the focus of the test. It would be better to be more explicit about what we're trying to test.

Modifications:

2 new tests:
   * client bootstrap creation.
   * connection establishment.
 (Data transfer is already covered by the ping_pong test)

Result:

Easier to assess the impact of changes to memory allocation patterns.
2020-05-28 16:17:20 +01:00
Peter AdamsandCory Benfield b174051b81 Supply allocation limits for UDP allocation tests (#1523)
Motivation:

Values were previously missing (5.3) or incorrectly specified (5.1)
meaning that allocations were not checked in for these swift versions.

Modifications:

Correct variable name in 5.1, add missing variables in 5.3 docker files.

Result:

UDP allocations will be checked.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-05-18 08:34:56 +01:00
9afac5ecda UDP based allocation tests (#1496)
UDP based allocation tests (#1496)

Motivation:

With future work being considered in the UDP space it will be useful to have a baseline measure of allocations.

Modifications:

New allocation tests for UDP -
Ideas inspired by the TCP allocation tests.
Code a modified version of UDPEchoServer and UDPEchoClient examples.

Result:

There are UDP based allocation tests.

Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-05-04 11:36:23 +01:00
David Evans 8da802c5eb Add 5.3 CI (#1498) 2020-05-01 19:17:44 +01:00
Johannes WeissandCory Benfield 2ad77f9a9b WIP: universal bootstrap (#1323)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-03-18 16:20:19 +00:00
Johannes Weiss a8fe2f343b SR-12094 is fixed, no need to skip tests (#1371) 2020-02-01 10:28:06 +00:00
tomer doron 25583d5ad8 improve docker security (#1375)
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:40:06 +00:00
George Barnett b4483e5c49 Avoid curried thunks (workaround SR-12115) (#1374)
Motivation:

Calling `function(otherFunction)` allocates, but
`function({ otherFunction($0) }` does not.

See: SR-12115 and SR-12116.

Modifications:

Avoid passing functions directly; pass them in new closures instead.

Result:

Fewer allocations.
2020-01-31 17:57:30 +00:00
Johannes Weissandtomer doron 7f8e96cf02 fix 5.2 builds (#1366)
motivation: tsan is broken on ubuntu 18.04.use 16.04 so 5.2 build can pass

changes:
* change 5.2 docker setup to use 16.04 instead of 18.04
* add the ability to pipe arguments to the integration tests via the docker setup
* skip tests_02 integration tests suite since it broken on 5.2 (swift-pm issue?)

fake the new limits from #1362

Co-authored-by: tomer doron <tomer@apple.com>
2020-01-29 14:39:28 +00:00
Fabian Fett 5dc9083c6a Recursive file reading not building up EventLoopFuture chain (#1353)
* Recursive file reading not building up EventLoopFuture chain

# Motivation:

After a long discussion with @adam-fowler today in aws-sdk-swift about how to recursively build a streaming interface (see https://github.com/swift-aws/aws-sdk-swift-core/pull/181), we came to the conclusion that it’s probably for the best not to build up an EventLoopFuture chain, since all EventLoopFutures are kept in memory while iterating. It would be better to create a promise that is captured by the recursive function, because in this case the internal EventLoopFutures can be released.

The memory footprint should be O(1) instead O(n) with a EventLoopFuture chain.

Later today, @adam-fowler made me aware of this code in NIO and that it uses a chain.

# Modifications:

```swift
_read(remainingReads: Int, bytesReadSoFar: Int64)
```

The internal read function no longer returns an EventLoopFuture. All Futures end with an `whenSuccess` or `whenFailure` case.

# Result:

From my understanding the memory footprint should be reduced when reading large files. The interface stays completely the same.
2020-01-27 13:33:50 +00:00
Johannes Weiss d3afb073e0 adding an extra test for reading many chunks (#1356)
* adding an extra test for reading many chunks

* Update docker-compose.1804.50.yaml
2020-01-27 10:36:45 +00:00
tomer doron 03f21c251a fix docker setup for development snapshots (#1357)
motivation: test against 5.2 development snapshots

changes:
* update Dockerfile so that a custom base image can be selected
* update 5.2 docker-compose file to use the nighly docker images for 5.2
2020-01-25 09:37:21 +00:00
Johannes Weiss 1b8e440808 docker: support Swift 5.2 dev snapshots (#1343)
Motivation:

We need to test on 5.2.

Modifications:

Add 5.2 dev snapshots to the docker setup.

Result:

More testing.
2020-01-16 17:52:14 +00:00
Johannes Weiss 7314c59733 add an allocation counter test for scheduling tasks (#1315)
* add an allocation counter test for scheduling tasks

Motivation:

Scheduling tasks is important so we should have an allocation counter
test.

Modifications:

add one

Result:

more alloc counter tests

* Update test_schedule_10000_tasks.swift

* Update docker-compose.1804.50.yaml

* Update docker-compose.1604.51.yaml
2019-12-18 22:27:12 +00:00
Johannes Weiss 50170fea8e Update docker-compose.1604.51.yaml (#1312) 2019-12-17 21:59:17 +00:00
Johannes Weiss eee18dc81f save allocations on connect (#1290)
Motivation:

ClientBootstrap.connect was needlessly overallocaing (for a needless
promise and a needless cascade).

Modifications:

Remove the needless allocations.

Result:

Fewer allocations.
2019-12-06 16:55:51 +00:00
Johannes Weiss d5ac36e60f optimise future callback collection (#1293)
Motivation:

The futures implementation used a particularly inefficient way to
accumulate all callbacks.

Modifications:

Improved this by allocating fewer arrays.

Result:

Fewer allocations.
2019-12-06 14:37:11 +00:00
Johannes Weiss 88c7994869 stop using AtomicBox (#1289)
Motivation:

AtomicBox doesn't properly work (#1286) and despite fixing it in #1287,
it's really not worth using AtomicBox (which as of #1287 instroduces a
CAS loop) anymore.

Modifications:

Remove the two uses of AtomicBox.

Result:

No usage of broken/slow data types.
2019-12-05 19:04:06 +00:00
Jake 3c879ebbaf Fast atomics (#1263)
Motivation:

The existing Atomic class holds an UnsafeEmbeddedAtomic which holds an OpaquePointer to raw memory for the C atomic. This results in multiple allocations on init. The new NIOAtomic class uses ManagedBufferPointer which tail allocates memory for the C atomic as part of the NIOAtomic class allocation.

Modifications:

Created NIOAtomic class that uses ManagedBufferPointer to allocate memory for the C atomic. Created version of catmc_atomic_* C functions that expect memory to be allocated/deallocated by caller. Created NIOAtomicPrimitive protocol for the new version of catmc_atomic_* functions.

Result:

Purely additive. NIOAtomic is available as a replacement for Atomic which results in fewer memory allocations.
2019-11-28 07:45:05 +00:00
George Barnett 302dee3e1a Make ByteBufferView mutable (#1208)
Motivation:

ByteBufferView isn't a mutable collection, but it probably should be.

Modifications:

- Add `copyBytes(at:to:length)` to `ByteBuffer` to copy bytes from a
  readable region of a buffer to another part of the buffer
- Conform `ByteBufferView` to `MutableCollection`, `RangeReplaceableCollection`
  and `MutableDataProtocol`
- Add an allocation counting test

Result:

`ByteBufferView` is now mutable.
2019-11-27 10:25:15 +00:00
Johannes Weiss 23d546e1fc EventLoopFuture: save one allocation per future (#1224)
Motivation:

Every EventLoopFuture was allocating an atomic boolean (which needs to
heap allocate because Swift) literally just to make the leakage checker
work. But the leakage checker is only active in debug mode, the
allocation however was _always_ done.

Modifications:

Remove the allocation in release mode (by making the atomic optional).

Result:

Fewer allocations
2019-11-11 09:48:36 +00:00
Marli Oshlack e4356bd005 Cow-box WebSocketFrame. (#1211)
Motivation:

WebSocketFrameDecoder makes an allocation due to WebSocketFrame not fitting in an
existential. We should reduce this overhead.

Modifications:

Moved data and extensionData into a cow-box and reorder fields to more efficiently
pack them.

Result:

WebSocketFrame is now 14 bytes, down from 55.
2019-11-08 12:27:06 +00:00
Marli Oshlack 05616c5119 Added an allocation benchmark for WebSocketFrameDecoder. (#1210) 2019-10-30 17:41:20 +01:00
Johannes Weiss e102aa9ae9 add PipeChannel (#1138)
Motivation:

There are use-cases for SwiftNIO where there are no actual sockets but
rather two pipe file descriptors - one for input, one for output.
There's no real reason why SwiftNIO shouldn't work for those.

Modifications:

Add a PipeChannel.

Result:

More use-cases for SwiftNIO.
2019-10-16 22:06:55 -07:00
Cory Benfield a796af1a96 Reduce allocations in WebSocketFrameEncoder. (#1161)
Motivation:

The WebSocketFrameEncoder naively allocated a new block to write the
frame header into every time it wrote. This is excessive: in many cases
it would be able to re-use the same buffer as last time.

Modifications:

- Attempt to re-use the buffer we used for the last header.

Result:

Fewer allocations in some applications.
2019-10-15 15:45:26 -07:00
Cory Benfield 37873bb265 Add some websocket encode benchmarks. (#1159)
Motivation:

To improve the performance of a given component it is very helpful to
know how it performs! This patch adds benchmarks and allocation counter
tests to NIO for websocket frame encoding.

Modifications:

- Wrote some benchmarks for WebSocket frame encoding.
- Wrote some allocation counter tests for WebSocket frame encoding.
- Extend the allocation counter tests to properly account for sub-tests

Result:

Better insight
2019-10-11 16:04:08 +01:00
tomer doron f548a29a27 swift 5.1 docker setup (#1146)
motivation: support swift 5.1 release

changes:
* update docker file to use official docker images
* update swift 5.0 and swift 5.1 docker-compose setup to use the official docker images
2019-09-24 12:38:39 -07:00
Johannes Weiss fbb977d5c2 DEVELOPMENT-SNAPSHOT-2019-09-05-a (#1132) 2019-09-09 10:12:16 +01:00
Johannes Weiss b6067bd531 enable TSan (#1130)
Motivation:

TSan is now supported in Swift 5.1 for Linux.

Modifications:

Enable TSan on 5.1.

Result:

More validation in the tests.
2019-09-09 09:27:56 +01:00
Johannes Weiss 4e1db157cc DEVELOPMENT-SNAPSHOT-2019-08-29-a (#1125) 2019-09-03 16:55:24 +01:00
Johannes Weiss 5224cfbfd7 DEVELOPMENT-SNAPSHOT-2019-08-15-a (#1113) 2019-08-16 19:05:29 +01:00
Johannes Weiss 4cef48e760 DEVELOPMENT-SNAPSHOT-2019-07-25-a (#1086)
* DEVELOPMENT-SNAPSHOT-2019-07-28-a

* Update docker-compose.1604.51.yaml
2019-07-30 09:22:46 +01:00
Johannes Weiss d9dc73592b 5.1-DEVELOPMENT-SNAPSHOT-2019-07-19-a (#1079) 2019-07-20 19:50:51 +01:00
tomer doron eeac3d51d9 add swift-api-digester docker setup (#1067)
motivation: prepare to run swift-api-digester in ci

changes:
* add jq to docker setup
* remove redundant ruby setting from docker file
2019-07-16 17:48:40 -07:00
Johannes Weiss c71df779ba 5.1 DEVELOPMENT-SNAPSHOT-2019-07-09-a (#1062) 2019-07-11 21:25:37 +01:00
Johannes Weiss 7f20464df3 enable TCP_NODELAY by default (#1020)
Motivation:

Networking software like SwiftNIO that always has explicit flushes
usually does not benefit from having TCP_NODELAY switched off. The
benefits of having it turned on are usually quite substantial and yet we
forced our users for the longest time to enable it manually.

Quite a bit of engineering time has been lost finding performance
problems and it turns out switching TCP_NODELAY on solves them
magically.

Netty has made the switch to TCP_NODELAY on by default, SwiftNIO should
follow.

Modifications:

Enable TCP_NODELAY by default.

Result:

If the user forgot to enable TCP_NODELAY, their software should now be
faster.
2019-06-19 18:04:01 +01:00
Johannes Weiss 39e60dd694 5.1-DEVELOPMENT-SNAPSHOT-2019-06-17-a (#1043) 2019-06-19 08:43:05 +01:00
Liam Flynn 57785e6d9c An HTTP upgrader class for a client pipeline. (#1001)
* Reorder ‘channel active’ calls to the same order as `_ChannelInboundHandler` and their likely chronological order.

Motivation:
When first viewing the example classes, coming to the ‘read’ method first, leaves the subject unclear as to what the method is ‘reading’.
It is preferable to view something being sent first, and then to view the reading of the response.
It also matches the call order against the protocol making it a little easier for those unfamiliar with the protocol to see which methods have been implemented.

Modifications:
Moved channel active calls to be top of the class.
Despite the diff there are no actual code modifications.
UDP Client changed to indent using spaces to match rest of project. Incidental change.

Result:
The examples are slighter clearer to read, particularly for newcomers to swift-no as the calls are in a logical chronological order.

* Fix an error in the upgrader and its tests which checked the connection header incorrectly.

Motivation:
To correct the logic in the upgrader. Previously it checked if the upgraders required headers include the connection header. Now it checks that the connection header value was present as a separate header in the incoming request.
To prepare the class naming for the presence of a client upgrader.

Modifications:
Slight change in server upgrader handler logic with accompanying tests.
Renamed upgrader and test files to include the word ‘server’.
Ran the linux test script.

Result:
The server upgrader now checks for the presence of the connection header value as a header of its own.

* Rename WebSocketServer upgrader to make the naming clearer and make way for a client version.

Motivation:

To make the web socket upgrader naming clearer, particularly once we add a client version.

Modifications:

Rename WebSocketUpgrader too WebSocketServerUpgrader.

Result:

Improved clarity of naming on the web socket upgrader.

* Adds  correct naming conventions to NIOWebSocketServerUpgrader. Sets back an incorrect fix (non-fix).

* Move deprecation for NIOWebSocketServerUpgrader typealias out of API shims file.

* Makes HTTPEncoder removable.
Adds a client upgrade handler with tests.
Adds the ability to use a client upgrader to the client setup.
Initial linux file update.

* Allow assertContains to be accessed publicly, so that it can be used in the client side tests.

* Update tests to remove server upgrader from client tests.
Change client tests to use Embedded channel.
Update HTTPUpgradeConfiguration class name to be NIOHTTPServerUpgradeConfiguration
Few other small stylistic changes.

* Removed awaiting upgrader state.
Removed future from handle upgrade call as is synchronous.
Removed protocol iterator from handle upgrade call as is not required by the client.

* Ensure that the client handler calls for the HTTPPipeline are backwards compatible.
Ensure that incoming promises to the handler write call are completed.
Neaten the upgrade header formation to remove looping.
Improve the correctness of the upgrade error throwing.

* Update scripts to match new unit tests.

* Change the documentation for HTTPServerPipeline to remove nil options which have now been removed.

* Restore an incorrectly added server pipeline comment change and make it to the client pipeline instead.

* Raise the allocation limits in the docker images to allow the tests to pass.
2019-06-16 11:10:12 +01:00
Johannes Weiss 8112653e28 alloc counters: disallow too high limits (#1022)
Motivation:

For the allocation counter tests to be as useful as possible, we should
disallow limits that are too high, we should capture the allocation
count very close to where it actually is.

Modifications:

Don't allow any allocation counter test to allocate fewer than
'limit - 1000' allocations.

Result:

Better limits.
2019-06-02 18:17:58 +01:00
Johannes Weiss 19aa7bf77d 5.1-DEVELOPMENT-SNAPSHOT-2019-05-29-a (#1021) 2019-05-30 14:08:30 +01:00