Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/spec/connection_stress_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.

//
// An example task specification for running a connection stress test in Trogdor.
// See TROGDOR.md for details.
//

{
"class": "org.apache.kafka.trogdor.workload.ConnectionStressSpec",
"durationMs": 60000,
"clientNode": "node0",
"bootstrapServers": "localhost:9092",
"targetConnectionsPerSec": 100,
"numThreads": 10,
"action": "CONNECT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public void start(Platform platform, WorkerStatusTracker status,
}
}

/**
* Update the worker's status.
* This method should be called inside a lock on the ConnectionStressWorker object
*/
private void updateStatus(long lastTimeMs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be synchronized since it accesses totalConnections, totalFailedConnections, etc. which are only ever accessed under the lock.

status.update(JsonUtil.JSON_SERDE.valueToTree(
new StatusData(totalConnections,
totalFailedConnections,
(totalConnections * 1000.0) / (lastTimeMs - startTimeMs))));
nextReportTime = lastTimeMs + REPORT_INTERVAL_MS;
}

private static class ConnectStressThrottle extends Throttle {
ConnectStressThrottle(int maxPerPeriod) {
super(maxPerPeriod, THROTTLE_PERIOD_MS);
Expand All @@ -130,10 +142,7 @@ public void run() {
conf.getList(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG),
conf.getString(AdminClientConfig.CLIENT_DNS_LOOKUP_CONFIG));
ManualMetadataUpdater updater = new ManualMetadataUpdater(Cluster.bootstrap(addresses).nodes());
while (true) {
if (doneFuture.isDone()) {
break;
}
while (!doneFuture.isDone()) {
throttle.increment();
long lastTimeMs = throttle.lastTimeMs();
boolean success = false;
Expand All @@ -150,13 +159,8 @@ public void run() {
if (!success) {
totalFailedConnections++;
}
if (lastTimeMs > nextReportTime) {
status.update(JsonUtil.JSON_SERDE.valueToTree(
new StatusData(totalConnections,
totalFailedConnections,
(totalConnections * 1000.0) / (lastTimeMs - startTimeMs))));
nextReportTime = lastTimeMs + REPORT_INTERVAL_MS;
}
if (lastTimeMs > nextReportTime)
updateStatus(lastTimeMs);
}
}
} catch (Exception e) {
Expand All @@ -165,7 +169,7 @@ public void run() {
}

private boolean attemptConnection(AdminClientConfig conf,
ManualMetadataUpdater updater) throws Exception {
ManualMetadataUpdater updater) {
try {
List<Node> nodes = updater.fetchNodes();
Node targetNode = nodes.get(ThreadLocalRandom.current().nextInt(nodes.size()));
Expand Down Expand Up @@ -250,6 +254,9 @@ public void stop(Platform platform) throws Exception {
doneFuture.complete("");
workerExecutor.shutdownNow();
workerExecutor.awaitTermination(1, TimeUnit.DAYS);
synchronized (ConnectionStressWorker.this) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though calling updateStatus() here is thread-safe, I think that using the lock here acts as a memory barrier and allows us to access the latest values of the variables. I very well might be wrong though and this may be superfluous

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not thread-safe without the synchronized, since we're accessing variables that need synchronization. But let's move the synchronized keyword into ConnectionStressWorker#updateStatus, as described above, since that's a bit cleaner

updateStatus(throttle.lastTimeMs());
}
this.workerExecutor = null;
this.status = null;
}
Expand Down