Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase maximum supported number of simultaneously active TCP connections (Photon) #1350

Merged
merged 7 commits into from Jan 22, 2018

Conversation

@sergeuz
Copy link
Member

commented Jul 5, 2017

Problem

Currently, the firmware allows up to 5 TCP connections (sockets) to be active at the same time. With one socket used by the system to communicate with the cloud, applications can establish (or accept) only 4 TCP connections.

Solution

Increase maximum number of simultaneously active TCP connections to 10. This requires increasing size of the LwIP's TCP PCBs (Protocol Control Blocks) pool from current 5 to 10 entries. The pool is allocated statically, so after this change static RAM usage in the part2 increases by ~800 bytes.

Ideally, we would also want to increase number of preallocated TX/RX buffers accordingly (currently there are 7 buffers available for each direction), but this doesn't seem to be feasible due to static RAM constraints.

Depending on the application's data flow, limited number of TX/RX buffers may lead to increased number of retransmissions between the peers and, in some cases, to connection errors. This PR includes a set of tests which stress-test the TCP implementation under various scenarios.

Steps to Test

Run wiring/tcp_client and app/tcp_server tests.

Example App

#include "application.h"

SYSTEM_MODE(MANUAL)

namespace {

const Serial1LogHandler logHandler(115200, LOG_LEVEL_WARN, {
    { "app", LOG_LEVEL_ALL }
});

const char* const SERVER_HOST = "216.58.209.78"; // Google
const unsigned SERVER_PORT = 80;

const int MAX_CONNECTIONS = 10;

} // namespace

void setup() {
    WiFi.connect();
    waitUntil(WiFi.ready);
    Vector<TCPClient> clients;
    for (int i = 0; i < MAX_CONNECTIONS; ++i) {
        Log.info("Opening connection %d of %d...", i + 1, MAX_CONNECTIONS);
        TCPClient c;
        if (c.connect(SERVER_HOST, SERVER_PORT)) {
            Log.info("OK");
            clients.append(c);
        } else {
            Log.error("Error");
            break;
        }
    }
}

void loop() {
}

References


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

TODO: Update reference docs


Enhancement

[PR #1350] [Photon/P1] Increase maximum supported number of simultaneously active TCP connections from 5 to 10 (cloud connection consumes 1).

@sergeuz sergeuz added this to the 0.8.0 milestone Jul 5, 2017

@sergeuz sergeuz requested a review from avtolstoy Jul 5, 2017

@sergeuz sergeuz added the enhancement label Jul 5, 2017

@m-mcgowan m-mcgowan modified the milestones: 0.8.0, 0.8.0-rc.2 Nov 24, 2017

@avtolstoy avtolstoy referenced this pull request Jan 15, 2018
4 of 6 tasks complete

@m-mcgowan m-mcgowan merged commit c6e57ab into fix/tcpserver-threading Jan 22, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@m-mcgowan m-mcgowan deleted the feature/max_tcp_conn_10 branch Jan 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.