Skip to content

Again: TCP server performance completely unuseful #1430

@nouser2013

Description

@nouser2013

Hi, I'm sorry to bring this up once more as it has been referenced several times now. But still, I cannot get a TCP server to put more than one packet in the send queue due to incorrect handling of the delayed ACK. Looking at the headers, there is the TCP_MSS set to 1460 and the TCP_WND four times that value. Hence, if the same thing is in the liblwip.a (and negotiation works correctly), we shouldn't have a problem.

What bothers me in particular is the following video https://www.youtube.com/watch?v=8ISbmQTbjDI where this guy sends websocket replies back to the client at about 220Hz. And they carry arrays of data. To be fair, he coded this with the FreeRTOS version without arduino intermediary layer.

BUT: why can't we have this?

WiFiServer tcpTelnetServer(23);
WiFiClient tcpTelnetClient; // Only one client at a time a.t.m.!

void setup() {
  tcpTelnetServer.begin();
}

void loop() {
  // HANDLE TCP TELNET SERVER
  if (!tcpTelnetClient.connected()) {
    tcpTelnetClient = tcpTelnetServer.available();
    if (tcpTelnetClient.connected()) {
      tcpTelnetClient.setNoDelay(true);
      Serial.println(" DBG: New TCP client connected...");
    }
  } else {
    // remember: Telnet sends \r or \r\n, NOT \n!
    if (tcpTelnetClient.available()) {
      char stringBuffer[300];
      tcpTelnetClient.readBytesUntil('\r', stringBuffer, sizeof(stringBuffer)-1);
      tcpTelnetClient.flush();
      // Process command...
      for (int i=0; i<6; i++) {
        memset(stringBuffer, 't', 60);
        stringBuffer[60] = 0; // Zeroterminate manually!
        Serial.printf("Before (%d): %d\n", i, micros());
        tcpTelnetClient.print(stringBuffer);
        Serial.printf("Middle (%d): %d\n", i, micros());
        tcpTelnetClient.write((uint8_t *)stringBuffer, strlen(stringBuffer));
        Serial.printf("After  (%d): %d\n\n", i, micros());
      }
    }
  }
}

this results in

Before (0): 46582971
Middle (0): 46785297
After  (0): 46984893

Before (1): 46985136
Middle (1): 47393106
After  (1): 47803031

Before (2): 47803275
Middle (2): 48212294
After  (2): 48621882

Before (3): 48622126
Middle (3): 48827013
After  (3): 49236314

Before (4): 49236558
Middle (4): 49647626
After  (4): 49854952

Before (5): 49855141
Middle (5): 50054827
After  (5): 50254701

*edit: MWE added..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions