-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: Update Trogdor ConnectionStressWorker status at the end of execution #6445
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
Changes from 1 commit
5dd2f91
1166afb
ca81397
82259ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
|
|
@@ -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) { | ||
| 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); | ||
|
|
@@ -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; | ||
|
|
@@ -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) { | ||
|
|
@@ -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())); | ||
|
|
@@ -250,6 +254,9 @@ public void stop(Platform platform) throws Exception { | |
| doneFuture.complete(""); | ||
| workerExecutor.shutdownNow(); | ||
| workerExecutor.awaitTermination(1, TimeUnit.DAYS); | ||
| synchronized (ConnectionStressWorker.this) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though calling
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not thread-safe without the |
||
| updateStatus(throttle.lastTimeMs()); | ||
| } | ||
| this.workerExecutor = null; | ||
| this.status = null; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.