Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -99,19 +99,32 @@ public void start(Platform platform, WorkerStatusTracker status,
log.info("{}: Activating ConnectionStressWorker with {}", id, spec);
this.doneFuture = doneFuture;
this.status = status;
this.totalConnections = 0;
this.totalFailedConnections = 0;
this.startTimeMs = TIME.milliseconds();
synchronized (ConnectionStressWorker.this) {

@stanislavkozlovski stanislavkozlovski Mar 14, 2019

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.

Had to add this here otherwise we got a FindBugs warning


IS | Inconsistent synchronization of org.apache.kafka.trogdor.workload.ConnectionStressWorker.nextReportTime; locked 66% of time
-- | --
  | Bug type IS2_INCONSISTENT_SYNC (click for details) In class org.apache.kafka.trogdor.workload.ConnectionStressWorkerField org.apache.kafka.trogdor.workload.ConnectionStressWorker.nextReportTimeSynchronized 66% of the timeUnsynchronized access at ConnectionStressWorker.java:[line 107]Synchronized access at ConnectionStressWorker.java:[line 124]Synchronized access at ConnectionStressWorker.java:[line 162]
IS | Inconsistent synchronization of org.apache.kafka.trogdor.workload.ConnectionStressWorker.startTimeMs; locked 50% of time
  | Bug type IS2_INCONSISTENT_SYNC (click for details) In class org.apache.kafka.trogdor.workload.ConnectionStressWorkerField org.apache.kafka.trogdor.workload.ConnectionStressWorker.startTimeMsSynchronized 50% of the timeUnsynchronized access at ConnectionStressWorker.java:[line 104]Synchronized access at ConnectionStressWorker.java:[line 120]
IS | Inconsistent synchronization of org.apache.kafka.trogdor.workload.ConnectionStressWorker.totalConnections; locked 66% of time
  | Bug type IS2_INCONSISTENT_SYNC (click for details) In class org.apache.kafka.trogdor.workload.ConnectionStressWorkerField org.apache.kafka.trogdor.workload.ConnectionStressWorker.totalConnectionsSynchronized 66% of the timeUnsynchronized access at ConnectionStressWorker.java:[line 102]Synchronized access at ConnectionStressWorker.java:[line 120]Synchronized access at ConnectionStressWorker.java:[line 120]
IS | Inconsistent synchronization of org.apache.kafka.trogdor.workload.ConnectionStressWorker.totalFailedConnections; locked 50% of time
  | Bug type IS2_INCONSISTENT_SYNC (click for details) In class org.apache.kafka.trogdor.workload.ConnectionStressWorkerField org.apache.kafka.trogdor.workload.ConnectionStressWorker.totalFailedConnectionsSynchronized 50% of the timeUnsynchronized access at ConnectionStressWorker.java:[line 103]Synchronized access at ConnectionStressWorker.java:[line 120]

(see IS2_INCONSISTENT_SYNC in http://findbugs.sourceforge.net/bugDescriptions.html)

this.totalConnections = 0;
this.totalFailedConnections = 0;
this.nextReportTime = 0;
this.startTimeMs = TIME.milliseconds();
}
this.throttle = new ConnectStressThrottle(WorkerUtils.
perSecToPerPeriod(spec.targetConnectionsPerSec(), THROTTLE_PERIOD_MS));
this.nextReportTime = 0;
this.workerExecutor = Executors.newFixedThreadPool(spec.numThreads(),
ThreadUtils.createThreadFactory("ConnectionStressWorkerThread%d", false));
for (int i = 0; i < spec.numThreads(); i++) {
this.workerExecutor.submit(new ConnectLoop());
}
}

/**
* Update the worker's status and next status report time.
*/
private synchronized void updateStatus(long lastTimeMs) {
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 +143,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 +160,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 +170,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 +255,7 @@ public void stop(Platform platform) throws Exception {
doneFuture.complete("");
workerExecutor.shutdownNow();
workerExecutor.awaitTermination(1, TimeUnit.DAYS);
updateStatus(throttle.lastTimeMs());
this.workerExecutor = null;
this.status = null;
}
Expand Down