2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* networktest.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/NetworkTest.h"
|
2019-08-22 09:37:50 +08:00
|
|
|
#include "flow/Knobs.h"
|
2018-08-11 06:18:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2020-06-22 18:37:16 +08:00
|
|
|
#include "flow/ActorCollection.h"
|
|
|
|
#include "flow/UnitTest.h"
|
|
|
|
#include <inttypes.h>
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
UID WLTOKEN_NETWORKTEST( -1, 2 );
|
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
struct LatencyStats {
|
2020-02-11 07:03:35 +08:00
|
|
|
using sample = double;
|
|
|
|
double x = 0;
|
|
|
|
double x2 = 0;
|
|
|
|
double n = 0;
|
|
|
|
|
|
|
|
sample tick() {
|
|
|
|
// now() returns the timestamp when we were scheduled; count
|
|
|
|
// all that time against this sample.
|
|
|
|
return now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tock(sample tick) {
|
|
|
|
// time_monotonic returns the timestamp when it was called;
|
|
|
|
// count the time it took us to be dispatched and invoke
|
|
|
|
// timer_monotonic
|
|
|
|
double delta = timer_monotonic() - tick;
|
|
|
|
x += delta;
|
|
|
|
x2 += (delta * delta);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
void reset() { *this = LatencyStats(); }
|
|
|
|
double count() { return n; }
|
|
|
|
double mean() { return x / n; }
|
|
|
|
double stddev() { return sqrt(x2 / n - (x / n) * (x / n)); }
|
2020-02-11 07:03:35 +08:00
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
NetworkTestInterface::NetworkTestInterface( NetworkAddress remote )
|
2018-10-25 05:59:50 +08:00
|
|
|
: test( Endpoint({remote}, WLTOKEN_NETWORKTEST) )
|
2017-05-26 04:48:44 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkTestInterface::NetworkTestInterface( INetwork* local )
|
|
|
|
{
|
2019-06-25 17:47:35 +08:00
|
|
|
test.makeWellKnownEndpoint( WLTOKEN_NETWORKTEST, TaskPriority::DefaultEndpoint );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> networkTestServer() {
|
|
|
|
state NetworkTestInterface interf( g_network );
|
|
|
|
state Future<Void> logging = delay( 1.0 );
|
|
|
|
state double lastTime = now();
|
|
|
|
state int sent = 0;
|
2020-02-20 02:55:05 +08:00
|
|
|
state LatencyStats latency;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
loop {
|
|
|
|
choose {
|
|
|
|
when( NetworkTestRequest req = waitNext( interf.test.getFuture() ) ) {
|
2020-02-20 02:55:05 +08:00
|
|
|
LatencyStats::sample sample = latency.tick();
|
2017-05-26 04:48:44 +08:00
|
|
|
req.reply.send( NetworkTestReply( Value( std::string( req.replySize, '.' ) ) ) );
|
2020-02-11 07:03:35 +08:00
|
|
|
latency.tock(sample);
|
2017-05-26 04:48:44 +08:00
|
|
|
sent++;
|
|
|
|
}
|
2018-08-11 04:57:10 +08:00
|
|
|
when( wait( logging ) ) {
|
2017-05-26 04:48:44 +08:00
|
|
|
auto spd = sent / (now() - lastTime);
|
2020-02-11 07:03:35 +08:00
|
|
|
if (FLOW_KNOBS->NETWORK_TEST_SCRIPT_MODE) {
|
2020-02-20 02:55:05 +08:00
|
|
|
fprintf(stderr, "%f\t%.3f\t%.3f\n", spd, latency.mean() * 1e6, latency.stddev() * 1e6);
|
2020-02-11 07:03:35 +08:00
|
|
|
} else {
|
2020-02-20 02:55:05 +08:00
|
|
|
fprintf(stderr, "responses per second: %f (%f us)\n", spd, latency.mean() * 1e6);
|
2020-02-11 07:03:35 +08:00
|
|
|
}
|
|
|
|
latency.reset();
|
2017-05-26 04:48:44 +08:00
|
|
|
lastTime = now();
|
|
|
|
sent = 0;
|
|
|
|
logging = delay( 1.0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
static bool moreRequestsPending(int count) {
|
2020-02-11 07:03:35 +08:00
|
|
|
if (count == -1) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
int request_count = FLOW_KNOBS->NETWORK_TEST_REQUEST_COUNT;
|
|
|
|
return (!request_count) || count < request_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
static bool moreLoggingNeeded(int count, int iteration) {
|
2020-02-11 07:03:35 +08:00
|
|
|
if (FLOW_KNOBS->NETWORK_TEST_SCRIPT_MODE) {
|
|
|
|
return iteration <= 2;
|
|
|
|
} else {
|
2020-02-20 02:55:05 +08:00
|
|
|
return moreRequestsPending(count);
|
2020-02-11 07:03:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
ACTOR Future<Void> testClient(std::vector<NetworkTestInterface> interfs, int* sent, int* completed,
|
|
|
|
LatencyStats* latency) {
|
|
|
|
state std::string request_payload(FLOW_KNOBS->NETWORK_TEST_REQUEST_SIZE, '.');
|
|
|
|
state LatencyStats::sample sample;
|
2020-02-11 07:03:35 +08:00
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
while (moreRequestsPending(*sent)) {
|
2017-05-26 04:48:44 +08:00
|
|
|
(*sent)++;
|
2020-02-11 07:03:35 +08:00
|
|
|
sample = latency->tick();
|
2020-02-20 02:55:05 +08:00
|
|
|
NetworkTestReply rep = wait(
|
|
|
|
retryBrokenPromise(interfs[deterministicRandom()->randomInt(0, interfs.size())].test,
|
|
|
|
NetworkTestRequest(StringRef(request_payload), FLOW_KNOBS->NETWORK_TEST_REPLY_SIZE)));
|
2020-02-11 07:03:35 +08:00
|
|
|
latency->tock(sample);
|
|
|
|
(*completed)++;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2020-02-11 07:03:35 +08:00
|
|
|
return Void();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-02-20 02:55:05 +08:00
|
|
|
ACTOR Future<Void> logger(int* sent, int* completed, LatencyStats* latency) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state double lastTime = now();
|
2020-02-11 07:03:35 +08:00
|
|
|
state int logged = 0;
|
|
|
|
state int iteration = 0;
|
2020-02-20 02:55:05 +08:00
|
|
|
while (moreLoggingNeeded(logged, ++iteration)) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( delay(1.0) );
|
2020-02-20 02:55:05 +08:00
|
|
|
auto spd = (*completed - logged) / (now() - lastTime);
|
2020-02-11 07:03:35 +08:00
|
|
|
if (FLOW_KNOBS->NETWORK_TEST_SCRIPT_MODE) {
|
|
|
|
if (iteration == 2) {
|
|
|
|
// We don't report the first iteration because of warm-up effects.
|
2020-02-20 02:55:05 +08:00
|
|
|
printf("%f\t%.3f\t%.3f\n", spd, latency->mean() * 1e6, latency->stddev() * 1e6);
|
2020-02-11 07:03:35 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-02-20 02:55:05 +08:00
|
|
|
fprintf(stderr, "messages per second: %f (%6.3f us)\n", spd, latency->mean() * 1e6);
|
2020-02-11 07:03:35 +08:00
|
|
|
}
|
|
|
|
latency->reset();
|
2017-05-26 04:48:44 +08:00
|
|
|
lastTime = now();
|
2020-02-11 07:03:35 +08:00
|
|
|
logged = *completed;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2020-02-11 07:03:35 +08:00
|
|
|
// tell the clients to shut down
|
|
|
|
*sent = -1;
|
|
|
|
return Void();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void networkTestnanosleep()
|
|
|
|
{
|
|
|
|
printf("nanosleep speed test\n");
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
printf("\nnanosleep(10) latencies:");
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
|
|
|
double before = timer_monotonic();
|
|
|
|
timespec tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_nsec = 10;
|
|
|
|
nanosleep(&tv, NULL);
|
|
|
|
double after = timer_monotonic();
|
|
|
|
|
|
|
|
printf(" %0.3lf", (after - before)*1e6);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nnanosleep(10) latency after 5ms spin:");
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
double a = timer_monotonic() + 5e-3;
|
2018-04-07 07:50:58 +08:00
|
|
|
while (timer_monotonic() < a) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
double before = timer_monotonic();
|
|
|
|
timespec tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_nsec = 10;
|
|
|
|
nanosleep(&tv, NULL);
|
|
|
|
double after = timer_monotonic();
|
|
|
|
printf(" %0.3lf", (after - before)*1e6);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nnanosleep(20000) latency:");
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
double before = timer_monotonic();
|
|
|
|
timespec tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_nsec = 20000;
|
|
|
|
nanosleep(&tv, NULL);
|
|
|
|
double after = timer_monotonic();
|
|
|
|
|
|
|
|
printf(" %0.3lf", (after - before)*1e6);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("nanosleep(20000) loop\n");
|
|
|
|
while (true) {
|
|
|
|
timespec tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_nsec = 20000;
|
|
|
|
nanosleep(&tv, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> networkTestClient( std:: string testServers ) {
|
|
|
|
if (testServers == "nanosleep") {
|
|
|
|
networkTestnanosleep();
|
|
|
|
//return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
state std::vector<NetworkTestInterface> interfs;
|
|
|
|
state std::vector<NetworkAddress> servers = NetworkAddress::parseList(testServers);
|
|
|
|
state int sent = 0;
|
2020-02-11 07:03:35 +08:00
|
|
|
state int completed = 0;
|
2020-02-20 02:55:05 +08:00
|
|
|
state LatencyStats latency;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
for( int i = 0; i < servers.size(); i++ ) {
|
|
|
|
interfs.push_back( NetworkTestInterface( servers[i] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
state std::vector<Future<Void>> clients;
|
2020-02-20 02:55:05 +08:00
|
|
|
for (int i = 0; i < FLOW_KNOBS->NETWORK_TEST_CLIENT_COUNT; i++) {
|
|
|
|
clients.push_back(testClient(interfs, &sent, &completed, &latency));
|
2020-02-11 07:03:35 +08:00
|
|
|
}
|
2020-02-20 02:55:05 +08:00
|
|
|
clients.push_back(logger(&sent, &completed, &latency));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( waitForAll( clients ) );
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
2018-04-07 07:50:58 +08:00
|
|
|
}
|
2020-06-22 18:37:16 +08:00
|
|
|
|
|
|
|
struct RandomIntRange {
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
int get() const {
|
|
|
|
return nondeterministicRandom()->randomInt(min, max + 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct P2PNetworkTest {
|
|
|
|
std::vector<Reference<IListener>> listeners;
|
|
|
|
std::vector<NetworkAddress> remotes;
|
|
|
|
int connectionsOut;
|
|
|
|
RandomIntRange msgBytes;
|
|
|
|
RandomIntRange idleMilliseconds;
|
|
|
|
|
|
|
|
double startTime;
|
|
|
|
int64_t bytesSent;
|
|
|
|
int64_t bytesReceived;
|
|
|
|
int sessionsIn;
|
|
|
|
int sessionsOut;
|
|
|
|
Standalone<StringRef> msgBuffer;
|
2020-06-22 20:15:24 +08:00
|
|
|
int sendRecvSize;
|
2020-06-22 18:37:16 +08:00
|
|
|
|
2020-06-23 04:37:13 +08:00
|
|
|
std::string statsString() {
|
2020-06-22 18:37:16 +08:00
|
|
|
double elapsed = now() - startTime;
|
2020-06-23 04:37:13 +08:00
|
|
|
std::string s = format("%.2f MB/s bytes in %.2f MB/s bytes out %.2f/s completed sessions in %.2f/s completed sessions out",
|
2020-06-22 18:37:16 +08:00
|
|
|
bytesReceived / elapsed / 1e6, bytesSent / elapsed / 1e6, sessionsIn / elapsed, sessionsOut / elapsed);
|
2020-06-23 04:37:13 +08:00
|
|
|
bytesSent = 0;
|
|
|
|
bytesReceived = 0;
|
|
|
|
sessionsIn = 0;
|
|
|
|
sessionsOut = 0;
|
|
|
|
startTime = now();
|
|
|
|
return s;
|
2020-06-22 18:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
P2PNetworkTest() {}
|
|
|
|
|
2020-06-22 20:15:24 +08:00
|
|
|
P2PNetworkTest(std::string listenerAddresses, std::string remoteAddresses, int connectionsOut, RandomIntRange msgBytes, RandomIntRange idleMilliseconds, int sendRecvSize)
|
|
|
|
: connectionsOut(connectionsOut), msgBytes(msgBytes), idleMilliseconds(idleMilliseconds), sendRecvSize(sendRecvSize) {
|
2020-06-22 18:37:16 +08:00
|
|
|
bytesSent = 0;
|
|
|
|
bytesReceived = 0;
|
|
|
|
sessionsIn = 0;
|
|
|
|
sessionsOut = 0;
|
|
|
|
msgBuffer = nondeterministicRandom()->randomAlphaNumeric(msgBytes.max);
|
|
|
|
|
|
|
|
if(!remoteAddresses.empty()) {
|
|
|
|
remotes = NetworkAddress::parseList(remoteAddresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!listenerAddresses.empty()) {
|
|
|
|
for(auto a : NetworkAddress::parseList(listenerAddresses)) {
|
|
|
|
listeners.push_back(INetworkConnections::net()->listen(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkAddress randomRemote() {
|
|
|
|
return remotes[nondeterministicRandom()->randomInt(0, remotes.size())];
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> readMsg(P2PNetworkTest *self, Reference<IConnection> conn) {
|
2020-06-22 20:15:24 +08:00
|
|
|
state Standalone<StringRef> buffer = makeString(self->sendRecvSize);
|
2020-06-22 18:37:16 +08:00
|
|
|
state int bytesToRead = sizeof(int);
|
|
|
|
state int writeOffset = 0;
|
|
|
|
state bool gotHeader = false;
|
|
|
|
|
2020-06-22 20:15:24 +08:00
|
|
|
// Fill buffer sequentially until the initial bytesToRead is read (or more), then read
|
|
|
|
// intended message size and add it to bytesToRead, continue if needed until bytesToRead is 0.
|
2020-06-22 18:37:16 +08:00
|
|
|
loop {
|
|
|
|
int len = conn->read((uint8_t *)buffer.begin() + writeOffset, (uint8_t *)buffer.end());
|
|
|
|
bytesToRead -= len;
|
|
|
|
self->bytesReceived += len;
|
2020-06-22 20:15:24 +08:00
|
|
|
writeOffset += len;
|
|
|
|
|
|
|
|
// If no size header yet but there are enough bytes, read the size
|
|
|
|
if(!gotHeader && bytesToRead <= 0) {
|
2020-06-22 18:37:16 +08:00
|
|
|
gotHeader = true;
|
2020-06-22 20:15:24 +08:00
|
|
|
bytesToRead += *(int *)buffer.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(gotHeader) {
|
2020-06-22 18:37:16 +08:00
|
|
|
if(bytesToRead == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ASSERT(bytesToRead > 0);
|
|
|
|
writeOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len == 0) {
|
|
|
|
wait(conn->onReadable());
|
|
|
|
wait( delay( 0, TaskPriority::ReadSocket ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> writeMsg(P2PNetworkTest *self, Reference<IConnection> conn) {
|
|
|
|
state UnsentPacketQueue packets;
|
|
|
|
state int msgSize = self->msgBytes.get();
|
|
|
|
|
|
|
|
PacketWriter writer(packets.getWriteBuffer(), nullptr, Unversioned());
|
|
|
|
writer.serializeBinaryItem(msgSize);
|
|
|
|
writer.serializeBytes(self->msgBuffer.substr(0, msgSize));
|
|
|
|
|
|
|
|
loop {
|
|
|
|
wait(conn->onWritable());
|
|
|
|
wait( delay( 0, TaskPriority::WriteSocket ) );
|
2020-06-22 20:15:24 +08:00
|
|
|
int len = conn->write(packets.getUnsent(), self->sendRecvSize);
|
2020-06-22 18:37:16 +08:00
|
|
|
self->bytesSent += len;
|
|
|
|
packets.sent(len);
|
|
|
|
|
|
|
|
if(packets.empty())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-06-23 04:37:13 +08:00
|
|
|
ACTOR static Future<Void> doSession(P2PNetworkTest *self, Reference<IConnection> conn, bool accept) {
|
2020-06-22 18:37:16 +08:00
|
|
|
try {
|
2020-06-23 04:37:13 +08:00
|
|
|
if(accept) {
|
|
|
|
wait(conn->acceptHandshake());
|
|
|
|
} else {
|
|
|
|
wait(conn->connectHandshake());
|
|
|
|
}
|
2020-06-22 18:37:16 +08:00
|
|
|
wait(readMsg(self, conn) && writeMsg(self, conn));
|
|
|
|
wait(delay(self->idleMilliseconds.get() / 1e3));
|
|
|
|
conn->close();
|
2020-06-23 06:40:04 +08:00
|
|
|
if(accept) {
|
|
|
|
++self->sessionsIn;
|
|
|
|
} else {
|
|
|
|
++self->sessionsOut;
|
|
|
|
}
|
|
|
|
|
2020-06-22 18:37:16 +08:00
|
|
|
} catch(Error &e) {
|
2020-06-22 20:15:24 +08:00
|
|
|
printf("doSession: error %s on remote %s\n", e.what(), conn->getPeerAddress().toString().c_str());
|
2020-06-22 18:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> outgoing(P2PNetworkTest *self) {
|
|
|
|
loop {
|
2020-06-22 20:15:24 +08:00
|
|
|
wait(delay(0, TaskPriority::WriteSocket));
|
2020-06-22 18:37:16 +08:00
|
|
|
state NetworkAddress remote = self->randomRemote();
|
2020-06-22 20:15:24 +08:00
|
|
|
|
2020-06-22 18:37:16 +08:00
|
|
|
try {
|
2020-06-22 20:15:24 +08:00
|
|
|
state Reference<IConnection> conn = wait(INetworkConnections::net()->connect(remote));
|
2020-06-22 18:37:16 +08:00
|
|
|
//printf("Connected to %s\n", remote.toString().c_str());
|
2020-06-23 04:37:13 +08:00
|
|
|
wait(doSession(self, conn, false));
|
2020-06-22 18:37:16 +08:00
|
|
|
} catch(Error &e) {
|
2020-06-22 20:15:24 +08:00
|
|
|
printf("outgoing: error %s on remote %s\n", e.what(), remote.toString().c_str());
|
2020-06-22 18:37:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> incoming(P2PNetworkTest *self, Reference<IListener> listener) {
|
|
|
|
state ActorCollection sessions(false);
|
|
|
|
|
|
|
|
loop {
|
2020-06-22 20:15:24 +08:00
|
|
|
wait(delay(0, TaskPriority::AcceptSocket));
|
|
|
|
|
2020-06-22 18:37:16 +08:00
|
|
|
try {
|
2020-06-22 20:15:24 +08:00
|
|
|
state Reference<IConnection> conn = wait(listener->accept());
|
2020-06-22 18:37:16 +08:00
|
|
|
//printf("Connected from %s\n", conn->getPeerAddress().toString().c_str());
|
2020-06-23 04:37:13 +08:00
|
|
|
sessions.add(doSession(self, conn, true));
|
2020-06-22 18:37:16 +08:00
|
|
|
} catch(Error &e) {
|
2020-06-22 20:15:24 +08:00
|
|
|
printf("incoming: error %s on listener %s\n", e.what(), listener->getListenAddress().toString().c_str());
|
2020-06-22 18:37:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> run_impl(P2PNetworkTest *self) {
|
|
|
|
state ActorCollection actors(false);
|
2020-06-22 20:15:24 +08:00
|
|
|
|
2020-06-22 18:37:16 +08:00
|
|
|
self->startTime = now();
|
|
|
|
|
2020-06-22 20:15:24 +08:00
|
|
|
printf("%d listeners, %d remotes, %d outgoing connections\n", self->listeners.size(), self->remotes.size(), self->connectionsOut);
|
|
|
|
printf("Message size %d to %d bytes\n", self->msgBytes.min, self->msgBytes.max);
|
|
|
|
printf("Post exchange delay %f to %f seconds\n", self->idleMilliseconds.min / 1e3, self->idleMilliseconds.max / 1e3);
|
|
|
|
printf("Send/Recv size %d bytes\n", self->sendRecvSize);
|
2020-06-22 18:37:16 +08:00
|
|
|
|
|
|
|
for(auto n : self->remotes) {
|
|
|
|
printf("Remote: %s\n", n.toString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto el : self->listeners) {
|
|
|
|
printf("Listener: %s\n", el->getListenAddress().toString().c_str());
|
|
|
|
actors.add(incoming(self, el));
|
|
|
|
}
|
|
|
|
|
2020-06-22 20:15:24 +08:00
|
|
|
if(!self->remotes.empty()) {
|
|
|
|
for(int i = 0; i < self->connectionsOut; ++i) {
|
|
|
|
actors.add(outgoing(self));
|
|
|
|
}
|
2020-06-22 18:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loop {
|
|
|
|
wait(delay(1.0));
|
|
|
|
printf("%s\n", self->statsString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> run() {
|
|
|
|
return run_impl(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
int getEnvInt(const char *name, int defaultValue = 0) {
|
|
|
|
const char *val = getenv(name);
|
|
|
|
return val != nullptr ? atol(val) : defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getEnvStr(const char *name, std::string defaultValue = "") {
|
|
|
|
const char *val = getenv(name);
|
|
|
|
return val != nullptr ? val : defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Remove this hacky thing and make a "networkp2ptest" role in fdbserver
|
|
|
|
TEST_CASE("!p2ptest") {
|
|
|
|
state P2PNetworkTest p2p(
|
2020-06-22 20:15:24 +08:00
|
|
|
getEnvStr("listenerAddresses", "127.0.0.1:5000,127.0.0.1:5001:tls"),
|
|
|
|
getEnvStr("remoteAddresses", "127.0.0.1:5000,127.0.0.1:5001:tls"),
|
|
|
|
getEnvInt("connectionsOut", 2),
|
|
|
|
{getEnvInt("minMsgBytes", 0), getEnvInt("maxMsgBytes", 1000000)},
|
|
|
|
{getEnvInt("minIdleMilliseconds", 500), getEnvInt("maxIdleMilliseconds", 1000)},
|
|
|
|
getEnvInt("sendRecvSize", 32000)
|
2020-06-22 18:37:16 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
wait(p2p.run());
|
|
|
|
return Void();
|
|
|
|
}
|