nim-chronos/chronos.nimble
Jacek Sieka c25fa1f6cd
posix: fast path for write (#244)
When `write` is called on a `StreamTransport`, the current sequence of
operations is:

* copy data to queue
* register for "write" event notification
* return unfinished future to `write` caller
* wait for "write" notification (in `poll`)
* perform one `send`
* wait for notification again if there's more data to write
* complete the future

In this PR, we introduce a fast path for writing:

* If the queue is empty, try to send as much data as possible
  * If all data is sent, return completed future without `poll` round
  * If there's more data to send than can be sent in one go, add the
rest to queue
* If the queue is not empty, enqueue as above
* When notified that write is possible, keep writing until OS buffer is
full before waiting for event again

The fast path provides significant performance benefits when there are
many small writes, such as when sending gossip to many peers, by
avoiding the poll loop and data copy on each send.

Also fixes an issue where the socket would not be removed from the
writer set if there were pending writes on close.
2021-12-08 11:35:27 +01:00

46 lines
1.4 KiB
Nim

packageName = "chronos"
version = "3.0.10"
author = "Status Research & Development GmbH"
description = "Chronos"
license = "Apache License 2.0 or MIT"
skipDirs = @["tests"]
### Dependencies
requires "nim > 1.2.0",
"stew",
"bearssl",
"httputils",
"https://github.com/status-im/nim-unittest2.git#head"
var commandStart = "nim c -r --hints:off --verbosity:0 --skipParentCfg:on --warning[ObservableStores]:off"
task test, "Run all tests":
var commands = @[
commandStart & " -d:useSysAssert -d:useGcAssert tests/",
commandStart & " -d:chronosStackTrace -d:chronosStrictException tests/",
commandStart & " -d:release tests/",
commandStart & " -d:release -d:chronosFutureTracking tests/",
]
when (NimMajor, NimMinor) >= (1, 5):
commands.add commandStart & " --gc:orc -d:chronosFutureTracking -d:release -d:chronosStackTrace tests/"
for testname in ["testall"]:
for cmd in commands:
let curcmd = cmd & testname
echo "\n" & curcmd
exec curcmd
rmFile "tests/" & testname
task test_libbacktrace, "test with libbacktrace":
var commands = @[
commandStart & " -d:release --debugger:native -d:chronosStackTrace -d:nimStackTraceOverride --import:libbacktrace tests/",
]
for testname in ["testall"]:
for cmd in commands:
let curcmd = cmd & testname
echo "\n" & curcmd
exec curcmd
rmFile "tests/" & testname