Skip to content

Consumer performance benchmark #140

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

Closed
Closed
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
63 changes: 63 additions & 0 deletions Benchmarks/Benchmarks/SwiftKafkaBenchmarkUtils/Utilities.swift
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need these utils? They seem like small overhead in the benchmarks themselves and I would rather have them defined there. Moreover I don't think we have to read anytime from the ENV. Let's just hardcode the ports etc.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the swift-kafka-client open source project
//
// Copyright (c) 2023 Apple Inc. and the swift-kafka-client project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of swift-kafka-client project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Crdkafka
import Foundation
import Kafka
import KafkaTestUtils
import Logging

public extension Logger {
static var testLogger: Logger {
var logger = Logger(label: "bench_log")
#if DEBUG
logger.logLevel = .debug
#else
logger.logLevel = .info
#endif
return logger
}
}

public let logger: Logger = .testLogger
public let kafkaHost: String = kafkaHostFromEnv()
public let kafkaPort: Int = kafkaPortFromEnv()
public let numOfMessages: UInt = .init(getFromEnv("MESSAGES_NUMBER") ?? "500000")!


public func benchLog(_ msg: @autoclosure () -> Logger.Message) {
// Just in case for debug
#if DEBUG
logger.debug(msg())
#endif
}

public func getFromEnv(_ key: String) -> String? {
ProcessInfo.processInfo.environment[key]
}

public func kafkaHostFromEnv() -> String {
getFromEnv("KAFKA_HOST") ?? "localhost"
}

public func kafkaPortFromEnv() -> Int {
.init(getFromEnv("KAFKA_PORT") ?? "9092")!
}

public func bootstrapBrokerAddress() -> KafkaConfiguration.BrokerAddress {
.init(
host: kafkaHost,
port: kafkaPort
)
}
Loading