2015-09-09 08:59:49 +08:00
|
|
|
# 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.
|
|
|
|
|
2016-05-07 02:10:27 +08:00
|
|
|
import os
|
|
|
|
|
2024-12-14 01:14:31 +08:00
|
|
|
from kafkatest.services.kafka.util import fix_opts_for_new_jvm, get_log4j_config_param, get_log4j_config_for_tools
|
2015-09-09 08:59:49 +08:00
|
|
|
from kafkatest.services.performance import PerformanceService
|
2023-03-02 19:05:22 +08:00
|
|
|
from kafkatest.version import get_version, V_3_4_0, DEV_BRANCH
|
2015-09-09 08:59:49 +08:00
|
|
|
|
|
|
|
|
2016-05-06 04:12:11 +08:00
|
|
|
|
2015-09-09 08:59:49 +08:00
|
|
|
class EndToEndLatencyService(PerformanceService):
|
2016-04-14 04:50:49 +08:00
|
|
|
MESSAGE_BYTES = 21 # 0.8.X messages are fixed at 21 bytes, so we'll match that for other versions
|
2015-09-09 08:59:49 +08:00
|
|
|
|
2016-04-19 05:23:46 +08:00
|
|
|
# Root directory for persistent output
|
|
|
|
PERSISTENT_ROOT = "/mnt/end_to_end_latency"
|
|
|
|
LOG_DIR = os.path.join(PERSISTENT_ROOT, "logs")
|
|
|
|
STDOUT_CAPTURE = os.path.join(PERSISTENT_ROOT, "end_to_end_latency.stdout")
|
|
|
|
STDERR_CAPTURE = os.path.join(PERSISTENT_ROOT, "end_to_end_latency.stderr")
|
|
|
|
LOG_FILE = os.path.join(LOG_DIR, "end_to_end_latency.log")
|
|
|
|
CONFIG_FILE = os.path.join(PERSISTENT_ROOT, "client.properties")
|
|
|
|
|
2015-09-09 08:59:49 +08:00
|
|
|
logs = {
|
2016-04-19 05:23:46 +08:00
|
|
|
"end_to_end_latency_output": {
|
|
|
|
"path": STDOUT_CAPTURE,
|
|
|
|
"collect_default": True},
|
|
|
|
"end_to_end_latency_stderr": {
|
|
|
|
"path": STDERR_CAPTURE,
|
2015-09-09 08:59:49 +08:00
|
|
|
"collect_default": True},
|
2016-04-19 05:23:46 +08:00
|
|
|
"end_to_end_latency_log": {
|
|
|
|
"path": LOG_FILE,
|
|
|
|
"collect_default": True}
|
2015-09-09 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
2017-01-28 09:40:10 +08:00
|
|
|
def __init__(self, context, num_nodes, kafka, topic, num_records, compression_type="none", version=DEV_BRANCH, acks=1):
|
2017-08-30 07:41:19 +08:00
|
|
|
super(EndToEndLatencyService, self).__init__(context, num_nodes,
|
|
|
|
root=EndToEndLatencyService.PERSISTENT_ROOT)
|
2015-09-09 08:59:49 +08:00
|
|
|
self.kafka = kafka
|
2015-11-04 13:25:15 +08:00
|
|
|
self.security_config = kafka.security_config.client_config()
|
2023-03-02 19:05:22 +08:00
|
|
|
self.version = ''
|
2016-04-14 04:50:49 +08:00
|
|
|
|
2015-09-09 08:59:49 +08:00
|
|
|
self.args = {
|
|
|
|
'topic': topic,
|
|
|
|
'num_records': num_records,
|
2015-11-04 13:25:15 +08:00
|
|
|
'acks': acks,
|
2016-04-19 05:23:46 +08:00
|
|
|
'compression_type': compression_type,
|
2016-04-14 04:50:49 +08:00
|
|
|
'kafka_opts': self.security_config.kafka_opts,
|
|
|
|
'message_bytes': EndToEndLatencyService.MESSAGE_BYTES
|
2015-09-09 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 04:50:49 +08:00
|
|
|
for node in self.nodes:
|
|
|
|
node.version = version
|
|
|
|
|
|
|
|
def start_cmd(self, node):
|
|
|
|
args = self.args.copy()
|
2023-03-02 19:05:22 +08:00
|
|
|
self.version = get_version(node)
|
2015-09-09 08:59:49 +08:00
|
|
|
args.update({
|
2015-12-01 06:13:50 +08:00
|
|
|
'bootstrap_servers': self.kafka.bootstrap_servers(self.security_config.security_protocol),
|
2016-04-19 05:23:46 +08:00
|
|
|
'config_file': EndToEndLatencyService.CONFIG_FILE,
|
2017-08-30 07:41:19 +08:00
|
|
|
'kafka_run_class': self.path.script("kafka-run-class.sh", node),
|
|
|
|
'java_class_name': self.java_class_name()
|
2015-09-09 08:59:49 +08:00
|
|
|
})
|
|
|
|
|
2024-10-28 20:23:32 +08:00
|
|
|
cmd = fix_opts_for_new_jvm(node)
|
2024-12-14 01:14:31 +08:00
|
|
|
cmd += "export KAFKA_LOG4J_OPTS=\"%s%s\"; " % (get_log4j_config_param(node), get_log4j_config_for_tools(node))
|
2024-11-11 06:22:06 +08:00
|
|
|
cmd += "KAFKA_OPTS=%(kafka_opts)s %(kafka_run_class)s %(java_class_name)s " % args
|
|
|
|
cmd += "%(bootstrap_servers)s %(topic)s %(num_records)d %(acks)d %(message_bytes)d %(config_file)s" % args
|
2016-04-14 04:50:49 +08:00
|
|
|
|
2016-04-19 05:23:46 +08:00
|
|
|
cmd += " 2>> %(stderr)s | tee -a %(stdout)s" % {'stdout': EndToEndLatencyService.STDOUT_CAPTURE,
|
|
|
|
'stderr': EndToEndLatencyService.STDERR_CAPTURE}
|
2015-09-09 08:59:49 +08:00
|
|
|
|
2016-04-14 04:50:49 +08:00
|
|
|
return cmd
|
|
|
|
|
|
|
|
def _worker(self, idx, node):
|
2016-04-19 05:23:46 +08:00
|
|
|
node.account.ssh("mkdir -p %s" % EndToEndLatencyService.PERSISTENT_ROOT, allow_fail=False)
|
|
|
|
|
2024-12-14 01:14:31 +08:00
|
|
|
log_config = self.render(get_log4j_config_for_tools(node), log_file=EndToEndLatencyService.LOG_FILE)
|
2016-04-19 05:23:46 +08:00
|
|
|
|
2024-12-14 01:14:31 +08:00
|
|
|
node.account.create_file(get_log4j_config_for_tools(node), log_config)
|
2016-04-19 05:23:46 +08:00
|
|
|
client_config = str(self.security_config)
|
2024-11-11 06:22:06 +08:00
|
|
|
client_config += "compression_type=%(compression_type)s" % self.args
|
2016-04-19 05:23:46 +08:00
|
|
|
node.account.create_file(EndToEndLatencyService.CONFIG_FILE, client_config)
|
2016-05-07 02:10:27 +08:00
|
|
|
|
2016-04-14 04:50:49 +08:00
|
|
|
self.security_config.setup_node(node)
|
|
|
|
|
|
|
|
cmd = self.start_cmd(node)
|
2015-09-09 08:59:49 +08:00
|
|
|
self.logger.debug("End-to-end latency %d command: %s", idx, cmd)
|
|
|
|
results = {}
|
|
|
|
for line in node.account.ssh_capture(cmd):
|
|
|
|
if line.startswith("Avg latency:"):
|
|
|
|
results['latency_avg_ms'] = float(line.split()[2])
|
|
|
|
if line.startswith("Percentiles"):
|
|
|
|
results['latency_50th_ms'] = float(line.split()[3][:-1])
|
|
|
|
results['latency_99th_ms'] = float(line.split()[6][:-1])
|
|
|
|
results['latency_999th_ms'] = float(line.split()[9])
|
|
|
|
self.results[idx-1] = results
|
2017-08-30 07:41:19 +08:00
|
|
|
|
|
|
|
def java_class_name(self):
|
2023-03-02 19:05:22 +08:00
|
|
|
if self.version <= V_3_4_0:
|
|
|
|
return "kafka.tools.EndToEndLatency"
|
|
|
|
else:
|
|
|
|
return "org.apache.kafka.tools.EndToEndLatency"
|