Skip to content

Commit 6458cad

Browse files
committed
improve tls benchmark and inject tls verify delay
1 parent 2e66e3c commit 6458cad

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

fdbserver/networktest.actor.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* limitations under the License.
1919
*/
2020

21+
#include "flow/IRandom.h"
2122
#include "fmt/format.h"
2223
#include "fdbserver/NetworkTest.h"
2324
#include "flow/Knobs.h"
@@ -358,6 +359,10 @@ struct P2PNetworkTest {
358359
// Random delay before socket writes
359360
RandomIntRange waitWriteMilliseconds;
360361

362+
double randomCloseMaxDelay = -1; // Maximum delay before closing a connection
363+
364+
double probabilityNotCloseConn = 0;
365+
361366
double startTime;
362367
int64_t bytesSent;
363368
int64_t bytesReceived;
@@ -400,10 +405,13 @@ struct P2PNetworkTest {
400405
RandomIntRange requests,
401406
RandomIntRange idleMilliseconds,
402407
RandomIntRange waitReadMilliseconds,
403-
RandomIntRange waitWriteMilliseconds)
408+
RandomIntRange waitWriteMilliseconds,
409+
double randomCloseMaxDelay,
410+
double probabilityNotCloseConn)
404411
: connectionsOut(connectionsOut), requestBytes(sendMsgBytes), replyBytes(recvMsgBytes), requests(requests),
405412
idleMilliseconds(idleMilliseconds), waitReadMilliseconds(waitReadMilliseconds),
406-
waitWriteMilliseconds(waitWriteMilliseconds) {
413+
waitWriteMilliseconds(waitWriteMilliseconds), randomCloseMaxDelay(randomCloseMaxDelay),
414+
probabilityNotCloseConn(probabilityNotCloseConn) {
407415
bytesSent = 0;
408416
bytesReceived = 0;
409417
sessionsIn = 0;
@@ -494,18 +502,30 @@ struct P2PNetworkTest {
494502
return Void();
495503
}
496504

505+
ACTOR static Future<Void> randomDelayedConnClose(P2PNetworkTest* self, Reference<IConnection> conn) {
506+
wait(delay(deterministicRandom()->random01() * self->randomCloseMaxDelay / 1000.0));
507+
conn->close();
508+
return Void();
509+
}
510+
497511
ACTOR static Future<Void> doSession(P2PNetworkTest* self, Reference<IConnection> conn, bool incoming) {
498512
state int numRequests;
513+
state Future<Void> randomClose;
499514

500515
try {
501516
if (incoming) {
517+
if (self->randomCloseMaxDelay > -1) {
518+
randomClose = randomDelayedConnClose(self, conn);
519+
}
502520
wait(conn->acceptHandshake());
503-
504521
// Read the number of requests for the session
505522
Standalone<StringRef> buf = wait(readMsg(self, conn));
506523
ASSERT(buf.size() == sizeof(int));
507524
numRequests = *(int*)buf.begin();
508525
} else {
526+
if (self->randomCloseMaxDelay > -1) {
527+
randomClose = randomDelayedConnClose(self, conn);
528+
}
509529
wait(conn->connectHandshake());
510530

511531
// Pick the number of requests for the session and send it to remote
@@ -532,7 +552,9 @@ struct P2PNetworkTest {
532552
}
533553

534554
wait(delay(self->idleMilliseconds.get() / 1e3));
535-
conn->close();
555+
if (deterministicRandom()->random01() > self->probabilityNotCloseConn) {
556+
conn->close();
557+
}
536558

537559
if (incoming) {
538560
++self->sessionsIn;
@@ -653,7 +675,9 @@ TEST_CASE(":/network/p2ptest") {
653675
params.get("requests").orDefault("10:10000"),
654676
params.get("idleMilliseconds").orDefault("0"),
655677
params.get("waitReadMilliseconds").orDefault("0"),
656-
params.get("waitWriteMilliseconds").orDefault("0"));
678+
params.get("waitWriteMilliseconds").orDefault("0"),
679+
params.getDouble("randomCloseMaxDelay").orDefault(-1),
680+
params.getDouble("probabilityNotCloseConn").orDefault(0.0));
657681

658682
wait(p2p.run());
659683
return Void();

flow/Knobs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void FlowKnobs::initialize(Randomize randomize, IsSimulated isSimulated) {
107107

108108
init( TLS_HANDSHAKE_ALWAYS_BACKGROUND, false );
109109
init( INJECT_TLS_HANDSHAKE_BUSYNESS_SEC, 0.0 );
110+
init( INJECT_TLS_HANDSHAKE_VERIFY_SEC, 0.0 );
110111

111112
//FlowTransport
112113
init( CONNECTION_REJECTED_MESSAGE_DELAY, 1.0 );

flow/TLSConfig.actor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ TLSPolicy::~TLSPolicy() {}
4242
#include <sstream>
4343
#include <utility>
4444
#include <boost/asio/ssl/context.hpp>
45+
#include <thread>
4546

4647
#include "flow/Platform.h"
4748
#include "flow/IAsyncFile.h"
@@ -147,6 +148,9 @@ void ConfigureSSLStream(Reference<TLSPolicy> policy,
147148
std::function<void(bool)> callback) {
148149
try {
149150
stream.set_verify_callback([policy, callback](bool preverified, boost::asio::ssl::verify_context& ctx) {
151+
if (FLOW_KNOBS->INJECT_TLS_HANDSHAKE_VERIFY_SEC > 0) {
152+
std::this_thread::sleep_for(std::chrono::duration<double>(FLOW_KNOBS->INJECT_TLS_HANDSHAKE_VERIFY_SEC));
153+
}
150154
bool success = policy->verify_peer(preverified, ctx.native_handle());
151155
if (!success) {
152156
if (policy->on_failure)

flow/include/flow/Knobs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class FlowKnobs : public KnobsImpl<FlowKnobs> {
128128

129129
bool TLS_HANDSHAKE_ALWAYS_BACKGROUND;
130130
double INJECT_TLS_HANDSHAKE_BUSYNESS_SEC;
131+
double INJECT_TLS_HANDSHAKE_VERIFY_SEC;
131132

132133
int DISABLE_ASSERTS;
133134
double QUEUE_MODEL_SMOOTHING_AMOUNT;

0 commit comments

Comments
 (0)