Commit Graph
1096 Commits
Author SHA1 Message Date
Johannes Weiß c1f2718786 fix undefined behaviour when loading integers (possibly misaligned) 2017-06-22 11:45:52 +01:00
Tom Doron a6bae8b759 linux support
motivation: be able to build and test on linux

changes:
* add dockerfile to create docker image running all toold required for testing on linux
* add readme with instruction on how to use the docker setup
* add script to generate linux tests mapping
* add .swift_version file to explicitly call out the swift version needed to build the project
* adjust code that did not build on linux, mainly casting between Int32 and Int
2017-06-21 10:58:28 -07:00
Johannes Weiß 8acf942565 fix memory leak when vector write call throws error 2017-06-21 15:37:42 +01:00
Norman Maurer dbb98eb905 Split ChannelHandler to ChannelInboundHandler and ChannelOutboundHandler
The mention change was done for performance reasons as often the user only either implement inbound or outbound operations per handler. The problem before was that we had to traverse the full list all the time even if the user was not really interested in either inbound or outbound events.

With this change we also split the doubly-linked-list into two linked-lists, one for inbound handlers and one for outbound handlers. This way we only need to traverse the handlers that are really interested in th event itself.

To give an idea about the impact of the change in terms of performance, here are some numbers.

Two ChannelInboundHandlers in the ChannelPipeline that do nothing and so just forward the events to the next handler in the pipeline:

Before:

`Bandwidth per channel: 18369.796⇅ Mbps (2296224.5 kBps)`

After:

`Bandwidth per channel: 20043.638⇅ Mbps (2505454.7 kBps)`
2017-06-21 14:35:33 +02:00
Norman Maurer f1f1829296 Call pipeline.removeHandlers() in a delayed fashion to ensure we are non executing pipeline code anymore 2017-06-21 08:34:22 +02:00
Norman Maurer f091d61576 Remove the overhead of the tail and head context in the ChannelPipeline by skip their ChannelHandler if no custom action must be taken.
Also move the readIfNeeded() logic to Channel as it really belongs there.

Before:

 `Bandwidth per channel: 19004.576⇅ Mbps (2375571.9 kBps)`

After:
 `Bandwidth per channel: 21851.957⇅ Mbps (2731494.6 kBps)`
2017-06-20 14:28:04 +02:00
Norman Maurer 57cd379950 More consistent handling of writable state changes, so it matches netty 2017-06-19 15:05:29 +02:00
Norman Maurer 255afbdeca Fix multiple bugs while handling writes:
- Correctly update the readerIndex when a partal write for writev happens
- Correctly keep on writing if there are more flushed writes
2017-06-19 11:11:49 +02:00
Norman Maurer 179ec9f9dd Use the correct typealias when set and get SocketOption 2017-06-17 08:04:40 +02:00
Norman Maurer d788dc6794 Ensure SocketOption uses the correct types on linux and macos by using typealias for each platform 2017-06-16 21:08:47 +02:00
Norman Maurer 28c61c43e4 Remove ByteBuffer.skipBytes(...) as its reduntant with moveWriterIndex(forwardBy(...) 2017-06-16 20:26:53 +02:00
Johannes Weiß ecbda69fa9 fix pipeline stall (when no reads were happening and write returned EWOULDBLOCK) 2017-06-16 17:46:50 +01:00
Norman Maurer dea2a44c49 Add missing @discardResult 2017-06-16 13:16:03 +01:00
Norman Maurer 2ca36ad86a Remove duplicated code and also remove @discardResult where it makes no sense 2017-06-16 13:14:23 +01:00
Johannes Weiss c34eb26196 make IOData methods public 2017-06-16 11:46:12 +01:00
Kevin Clark 474ddadf00 Perf optimizations
* Remove unneeded hashValue from Future

And use Lock instead of NSLock. Seeing modest perf improvements.

* Annotate Promise and Future with final

* Use pthread_self equality rather than Thread

Seeing a 5x speedup in microbenchmarks
2017-06-16 02:11:27 -07:00
Johannes Weiß b73bfdab70 remove some existentials by specialising the data type (IOData) 2017-06-15 19:43:49 +01:00
Norman Maurer 4a6ed01491 Implement Future.wait() so we not pay an extra price if not used and so optimize the fast-path 2017-06-15 19:00:51 +01:00
Norman Maurer a7811b7b2d Add ByteBuffer.write(buffer) and set(buffer) 2017-06-14 19:19:29 +02:00
Johannes Weiß ba791a0ed5 new byte buffer 2017-06-12 17:42:07 +01:00
Norman Maurer 980085078c Use generic to remove the need of a forced cast. 2017-06-14 13:11:42 +02:00
Norman Maurer 6182f66a35 Remove use of DispatchQueue which was used to workaround https://bugs.swift.org/browse/SR-5145.
The use of DispatchQueue introduced a lot of overhead because it dispatched th ework to many threads. This could lead to have only one thread doing the IO while many others the actual deinit.

As we already limit the number of PendingWrite instances that will be written via writev to writevLimit we only need to take special action on failAll(...) which may possibly release thousands of PendingWrite instances and so could trigger a stackoverflow.
2017-06-13 15:18:51 +02:00
Norman Maurer 4f6723a0b3 Ensure we always mark the flush checkpoint, even if we are waiting for writable() to be called.
Previously we did not correctly mark the flush checkpoint if a call to writable() by the EventLoop was pending. This could have the affect that when the user calls flush while we already registered for InterestedEvent.write or InterestedEvent.all not all messages in the PendingWrite datastructure were correctly marked as flushed and so not written at the end when the writable call happens.
2017-06-13 12:34:53 +02:00
Norman Maurer 126cde1496 Correctly calculate the amount of writes in respect to writeSpinCount 2017-06-13 08:51:54 +02:00
Norman Maurer 877ba45c06 If we were able to completely flush all pending bytes we need to reregister with .none to ensure we still hold a reference to Channel itself and so not have the ARC deinit it 2017-06-12 19:56:35 +02:00
Norman Maurer 58d0883b2d Fork Future-Swift and adjust it to ensure callback execution is always done on the EventLoop.
- Also remove all methods that use Dispatch for now as we not need these
- Ensure we will detect if the user calls a blocking method while on the EventLoop and crash to guard against deadlock
2017-06-12 13:44:10 +02:00
Norman Maurer c0a2810840 Port AdaptiveRecvByteBufferAllocator from netty and make it the default 2017-06-12 09:13:21 +02:00
Norman Maurer 186dfa70a0 Make FixedSizeRecvByteBufferAllocator a struct 2017-06-11 11:12:16 +02:00
Norman Maurer 34475f3ba4 Only do one buffer allocation per read loop and just make use of the fact that ByteBuffer is a struct and uses COW 2017-06-10 13:31:25 +02:00
Norman Maurer e3537e162b Port write buffer mark 2017-06-09 17:58:58 +02:00
Norman Maurer c6685c3e7c Use types to allow the compile to specialize the methods 2017-06-09 15:47:10 +02:00
Norman Maurer fce361e337 Tighten up visibility to allow the optimizer doing a better job 2017-06-09 11:16:59 +02:00
Kevin Clark c9c3651f29 Minor cleanup in byte buffer 2017-06-08 12:05:26 -07:00
Kevin Clark fc3e0fe384 ByteBuffer bounds checking fixes
This fixes a number of bounds checking issues, including changing the behavior of out of bounds access. Now if get is passed a negative value or a value beyond the size of the buffer, it explodes. If set is passed a negative value it also explodes, but values passed the end of the buffer continue to implicitly resize.
2017-06-08 11:51:41 -07:00
Johannes Weiß 12e48ebd4f TCO in doPendingWriteVectorOperation for Swift 4 2017-06-08 16:44:07 +01:00
Johannes Weiß 2522fa68aa Swift 3.2 (Swift 4 in Swift 3 mode) needs TCO workaround 2017-06-08 16:10:22 +01:00
Johannes Weiß 02ff223eba add faster (Static)String write path 2017-06-08 16:09:56 +01:00
Johannes Weiß 37cca97422 rename ByteBuffer.data to ByteBuffer.backingData (to refuse confusion) 2017-06-08 16:09:19 +01:00
Norman Maurer cd4866152d No need to allocate and free the iovec array all the time as we can just pin it on the EventLoop 2017-06-08 15:45:48 +02:00
Norman Maurer 0b78bbf4ed Not call EventLoop.reregister if the interestedEvents not changed 2017-06-08 13:11:50 +02:00
Norman Maurer 39715425d4 Guard against EBADF when processing write and read spin 2017-06-08 12:52:51 +02:00
Norman Maurer c0b9c691bb Correctly return true if the whole buffer is written. This regression was introduced by 9d00cf0191c33eaad5406f04112b318ad848e2c4 2017-06-08 12:15:43 +02:00
Norman Maurer aa1f7d04ed Tighten up API and access rights 2017-06-07 11:15:06 +02:00
Kevin Clark 329b474f45 Initial impl of EmbeddedChannel 2017-06-05 16:59:51 -07:00
Norman Maurer bec8f64a13 Correctly update readerIndex of ByteBuffer when partial written. Fix regression introduced by 9d00cf0191c33eaad5406f04112b318ad848e2c4 2017-06-07 19:12:05 +02:00
Johannes Weiß 312f6824b5 writev optimisation 2017-06-06 17:26:25 +01:00
Norman Maurer e8d60df8c2 Make naming more consistent and so make it more swift-like api 2017-06-06 22:06:47 +02:00
Norman Maurer bff55bbb3d Port write spin configuration option from netty 2017-06-06 17:13:49 +02:00
Norman Maurer 7d959a3b1a Not use lazy for perf reasons 2017-06-06 14:51:10 +02:00
Norman Maurer 2114a925aa Only use gathering write if we really have more then one buffer to write 2017-06-06 12:37:13 +02:00