Skip to content

Commit

Permalink
Increase AsyncStream and Transport default buffer size from 4096 to 1…
Browse files Browse the repository at this point in the history
…6384 bytes. (#506)

Make buffer sizes configurable at compile time.
  • Loading branch information
cheatfate authored Feb 14, 2024
1 parent be4923b commit 2e37a6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
11 changes: 10 additions & 1 deletion chronos/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ const
chronosHasRaises* = 0
## raises effect support via `async: (raises: [])`

chronosTransportDefaultBufferSize* {.intdefine.} = 16384
## Default size of chronos transport internal buffer.

chronosStreamDefaultBufferSize* {.intdefine.} = 16384
## Default size of chronos async stream internal buffer.

when defined(chronosStrictException):
{.warning: "-d:chronosStrictException has been deprecated in favor of handleException".}
# In chronos v3, this setting was used as the opposite of
Expand All @@ -113,7 +119,10 @@ when defined(debug) or defined(chronosConfig):
printOption("chronosEventEngine", chronosEventEngine)
printOption("chronosEventsCount", chronosEventsCount)
printOption("chronosInitialSize", chronosInitialSize)

printOption("chronosTransportDefaultBufferSize",
chronosTransportDefaultBufferSize)
printOption("chronosStreamDefaultBufferSize",
chronosStreamDefaultBufferSize)

# In nim 1.6, `sink` + local variable + `move` generates the best code for
# moving a proc parameter into a closure - this only works for closure
Expand Down
6 changes: 3 additions & 3 deletions chronos/streams/asyncstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

{.push raises: [].}

import ../asyncloop, ../asyncsync
import ../transports/common, ../transports/stream
import ../[config, asyncloop, asyncsync]
import ../transports/[common, stream]
export asyncloop, asyncsync, stream, common

const
AsyncStreamDefaultBufferSize* = 4096
AsyncStreamDefaultBufferSize* = chronosStreamDefaultBufferSize
## Default reading stream internal buffer size.
AsyncStreamDefaultQueueSize* = 0
## Default writing stream internal queue size.
Expand Down
10 changes: 5 additions & 5 deletions chronos/transports/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import std/[strutils]
import stew/[base10, byteutils]
import ".."/[asyncloop, osdefs, oserrno, handles]
import ".."/[config, asyncloop, osdefs, oserrno, handles]

from std/net import Domain, `==`, IpAddress, IpAddressFamily, parseIpAddress,
SockType, Protocol, Port, `$`
Expand All @@ -21,10 +21,10 @@ export Domain, `==`, IpAddress, IpAddressFamily, parseIpAddress, SockType,
Protocol, Port, toInt, `$`

const
DefaultStreamBufferSize* = 4096 ## Default buffer size for stream
## transports
DefaultDatagramBufferSize* = 65536 ## Default buffer size for datagram
## transports
DefaultStreamBufferSize* = chronosTransportDefaultBufferSize
## Default buffer size for stream transports
DefaultDatagramBufferSize* = 65536
## Default buffer size for datagram transports
type
ServerFlags* = enum
## Server's flags
Expand Down

0 comments on commit 2e37a6e

Please sign in to comment.