korlibs / korlibs/korlibs-io

Request: Support TCP Low Latency mode for TCP sockets. Also support QUICK ACK for TCP sockets.

Open
#18 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

## Introduction
When supporting networking in an application, we normally have the choice between TCP and UDP connections.
TCP is more reliable, but slower, and has some [algorithms](https://en.wikipedia.org/wiki/Nagle%27s_algorithm) that try to manage how packets are sent to optimize the bandwidth usage / network congestion.
UDP is faster, but less reliable as it does not guarantee that packets are received by the other party.

For cases where UDP is not an option, but where TCP's default algorithms cause too much delay in data traffic, several features and algorithms can be disabled to speed up the sending of TCP packets. Two of these examples are:
TCP_NODELAY (aka "TCP Low Latency" mode)
TCP_QUICKACK (aka "TCP No Delayed Ack")

KorGE currently lacks methods to manage these modes in "common" code.

## Suggestion
Add a parameter or method to allow enabling/disabling of 'low latency mode' and 'delayed ack' on TCP connections, either in the constructor or as a separate method (or both).

I don't know what methods Kotlin currently uses to map to platform specific socket implementations, but here are some examples of how to set this setting on specific platforms.

## Documentation Examples
[Kotlin JVM (TCP Quick Ack)](https://docs.oracle.com/en/java/javase/17/docs/api/jdk.net/jdk/net/ExtendedSocketOptions.html)
[Kotlin JVM (TCP Low Latency)](https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#setTcpNoDelay-boolean-):
`socket.setTcpNoDelay(bool: Boolean)`

[Kotlin Android](https://developer.android.com/reference/kotlin/java/net/Socket#setTcpNoDelay(kotlin.Boolean)):
`socket.setTcpNoDelay(bool: Boolean)`

[iOS (Swift)](https://developer.apple.com/documentation/network/nwprotocoltcp/options):
```
let tcp = NWProtocolTCP.Options.init()
tcp.noDelay = true
```
C (Native Platforms):
```
int i = 1;
setsockopt( iSock, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
setsockopt( iSock, IPPROTO_TCP, TCP_QUICKACK, (void *)&i, sizeof(i));
```

## Limitations

JavaScript does not support a 'setTCPNoDelay' option on the 'client-side' (browser)
However, it seems like some browsers already disable this option by default (eg.: [Chrome](https://stackoverflow.com/questions/33589745/disabling-nagles-algorithm-client-side-javascript))

Alternatively, someone suggested [this workaround](https://stackoverflow.com/questions/13373519/websocket-tcp-packets-clumping-together/13406438#13406438) that seems to work (but does double bandwidth usage)

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names no repository files or tests. Start by locating KorGE's common TCP socket abstraction and its JVM, Android, iOS/native, and browser implementations, then compare which platform APIs expose TCP_NODELAY and TCP_QUICKACK. Done means a consistent common API with supported platform behavior and documented limitations where browsers cannot provide the options.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, java, javascript, kotlin, swift
Domain
networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.