diff --git a/frameworks/Kotlin/pronghorn/README.md b/frameworks/Kotlin/pronghorn/README.md deleted file mode 100644 index 93c9b29a856..00000000000 --- a/frameworks/Kotlin/pronghorn/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# Pronghorn -This is the [Pronghorn Http Server](https://www.pronghorn.tech) portion of the [TechEmpower Framework Benchmarks](https://github.com/TechEmpower/FrameworkBenchmarks). - -## About -The Pronghorn HTTP Server is a low-level, high performance HTTP server written in [Kotlin](https://kotlinlang.org/). - -### Version -v0.1.2 : [https://github.com/pronghorn-tech/server/releases/tag/0.1.2](https://github.com/pronghorn-tech/server/releases/tag/0.1.2) - -## Test Types - -### Plaintext -url : `http://TFB-server:8080/plaintext` -source code : [TestServer.kt](src/main/kotlin/pronghorn/TestServer.kt) - -### Json Serialization -url : `http://TFB-server:8080/json` -source code : [JsonHandler.kt](src/main/kotlin/pronghorn/handlers/JsonHandler.kt) - -### Single Query -url : `http://TFB-server:8080/db` -source code : [MongoDBRequestSingleHandler.kt](src/main/kotlin/pronghorn/handlers/MongoDBRequestSingleHandler.kt) - -### Multiple Query -url : `http://TFB-server:8080/queries` -source code : [MongoDBRequestMultiHandler.kt](src/main/kotlin/pronghorn/handlers/MongoDBRequestMultiHandler.kt) - -### Data Updates -url : `http://TFB-server:8080/updates` -source code : [MongoDBRequestUpdatesHandler.kt](src/main/kotlin/pronghorn/handlers/MongoDBRequestUpdatesHandler.kt) - -### Fortunes -url : `http://TFB-server:8080/fortunes` -source code : [MongoDBRequestFortunesHandler.kt](src/main/kotlin/pronghorn/handlers/MongoDBRequestFortunesHandler.kt) - -## Additional Dependencies - -### Pronghorn Plugins -Pronghorn is by default a zero dependency library, but for the purpose of benchmarking these tests utilize three Pronghorn plugins for performance and logging : -* [JCTools Collections Plugin](https://github.com/pronghorn-tech/plugin-collections-jctools) - performance -* [OpenHFT Hashing Plugin](https://github.com/pronghorn-tech/plugin-hashing-openhft) - performance -* [SLF4J Logging Plugin](https://github.com/pronghorn-tech/plugin-logging-slf4j) - logging - -Additionally, database driven tests utilize the [Pronghorn MongoDB Driver Stream](https://github.com/pronghorn-tech/mongodb-driver-stream) which implements the MongoDB Driver's Stream interface via the [Pronghorn Coroutine Framework](https://github.com/pronghorn-tech/coroutines). This utilizes the cooperative nature of concurrency in Pronghorn to enable efficient multiplexing of database communication. - -### Third-Party Libraries -Beyond the Pronghorn plugins above, these tests utilize several third party libraries. - -#### JsonIter -Tests requiring json encoding utilize the [jsoniter](http://jsoniter.com/) library, as well as the [Javassist](http://jboss-javassist.github.io/javassist/) library for improved performance of jsoniter. - -#### MongoDB Async Driver -Database tests depend on the [async MongoDB driver](https://github.com/mongodb/mongo-java-driver/tree/master/driver-async). - -#### HTTL -The Fortunes test utilizes the [httl library](http://httl.github.io/en/) as the template engine. - -## Contact -For additional information, help, or corrections concerning Pronghorn or these tests contact info [at] pronghorn.tech diff --git a/frameworks/Kotlin/pronghorn/benchmark_config.json b/frameworks/Kotlin/pronghorn/benchmark_config.json deleted file mode 100644 index 25d32506609..00000000000 --- a/frameworks/Kotlin/pronghorn/benchmark_config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "framework": "pronghorn", - "tests": [{ - "default": { - "json_url": "/json", - "plaintext_url": "/plaintext", - "db_url": "/db", - "query_url": "/queries?queries=", - "fortune_url": "/fortunes", - "update_url": "/updates?queries=", - "port": 8080, - "approach": "Realistic", - "classification": "Platform", - "database": "MongoDB", - "framework": "None", - "language": "Kotlin", - "flavor": "None", - "orm": "Raw", - "platform": "Pronghorn", - "webserver": "None", - "os": "Linux", - "database_os": "Linux", - "display_name": "Pronghorn", - "notes": "", - "versus": "", - "tags": ["broken"] - } - }] -} diff --git a/frameworks/Kotlin/pronghorn/build.gradle b/frameworks/Kotlin/pronghorn/build.gradle deleted file mode 100644 index 2f99c271b12..00000000000 --- a/frameworks/Kotlin/pronghorn/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -group 'pronghorn' -version '0.1.0' - -buildscript { - ext { - pronghornVersion = '0.1.3' - kotlinVersion = '1.2.31' - } - - repositories { - jcenter() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - } -} - -apply plugin: 'kotlin' -apply plugin: 'application' - -mainClassName = "pronghorn.TestServerKt" - -applicationDefaultJvmArgs = ['-server', '-XX:+AggressiveOpts'] - -repositories { - mavenCentral() -} - -kotlin { - experimental { - coroutines 'enable' - } -} - -dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" - - compile 'ch.qos.logback:logback-classic:1.2.3' - - compile 'com.jsoniter:jsoniter:0.9.18' // json encoding library - compile 'org.javassist:javassist:3.22.0-GA' // needed for faster json encoding mode - compile 'org.mongodb:mongodb-driver-async:3.5.0' // async MongoDB driver - compile 'com.github.httl:httl:1.0.11' // simple template engine - - compile "tech.pronghorn:server:$pronghornVersion" - compile "tech.pronghorn:plugin-collections-jctools:$pronghornVersion" - compile "tech.pronghorn:plugin-hashing-openhft:$pronghornVersion" - compile "tech.pronghorn:plugin-logging-slf4j:$pronghornVersion" - compile "tech.pronghorn:mongodb-driver-stream:$pronghornVersion" -} diff --git a/frameworks/Kotlin/pronghorn/config.toml b/frameworks/Kotlin/pronghorn/config.toml deleted file mode 100644 index 0055eb6a69f..00000000000 --- a/frameworks/Kotlin/pronghorn/config.toml +++ /dev/null @@ -1,19 +0,0 @@ -[framework] -name = "pronghorn" - -[main] -urls.plaintext = "/plaintext" -urls.json = "/json" -urls.db = "/db" -urls.query = "/queries?queries=" -urls.update = "/updates?queries=" -urls.fortune = "/fortunes" -approach = "Realistic" -classification = "Platform" -database = "MongoDB" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = "Pronghorn" -webserver = "None" -versus = "" diff --git a/frameworks/Kotlin/pronghorn/pronghorn.dockerfile b/frameworks/Kotlin/pronghorn/pronghorn.dockerfile deleted file mode 100644 index 1c957c351cc..00000000000 --- a/frameworks/Kotlin/pronghorn/pronghorn.dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM gradle:4.7.0-jdk10 -USER root -WORKDIR /pronghorn -COPY build.gradle build.gradle -COPY settings.gradle settings.gradle -COPY src src - -EXPOSE 8080 - -CMD ["gradle", "--no-daemon", "run"] diff --git a/frameworks/Kotlin/pronghorn/settings.gradle b/frameworks/Kotlin/pronghorn/settings.gradle deleted file mode 100644 index 1a6e15ba157..00000000000 --- a/frameworks/Kotlin/pronghorn/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'pronghorn' diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/TestServer.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/TestServer.kt deleted file mode 100644 index 5b5fc7fe0a7..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/TestServer.kt +++ /dev/null @@ -1,29 +0,0 @@ -package pronghorn - -import ch.qos.logback.classic.Level -import com.jsoniter.output.EncodingMode -import com.jsoniter.output.JsonStream -import pronghorn.handlers.* -import pronghorn.utils.TestConfig -import pronghorn.utils.setLibraryLogging -import tech.pronghorn.http.HttpResponses -import tech.pronghorn.http.protocol.CommonContentTypes -import tech.pronghorn.server.HttpServer -import tech.pronghorn.server.requesthandlers.StaticHttpRequestHandler - -fun main(args: Array) { - JsonStream.setMode(EncodingMode.DYNAMIC_MODE) // enable faster Json encoding mode - setLibraryLogging(Level.WARN) // minimize logging from chatty libraries - - val helloWorldResponse = HttpResponses.OK("Hello, World!", CommonContentTypes.TextPlain) - val helloWorldHandler = StaticHttpRequestHandler(helloWorldResponse) - - val server = HttpServer(TestConfig.listenHost, TestConfig.listenPort) - server.registerUrlHandler("/plaintext", helloWorldHandler) - server.registerUrlHandlerGenerator("/json", { JsonHandler() }) - server.registerUrlHandlerGenerator("/db", { worker -> MongoDBRequestSingleHandler(worker) }) - server.registerUrlHandlerGenerator("/queries", { worker -> MongoDBRequestMultiHandler(worker) }) - server.registerUrlHandlerGenerator("/fortunes", { worker -> MongoDBRequestFortunesHandler(worker) }) - server.registerUrlHandlerGenerator("/updates", { worker -> MongoDBRequestUpdatesHandler(worker) }) - server.start() -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/JsonHandler.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/JsonHandler.kt deleted file mode 100644 index 40dfad25815..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/JsonHandler.kt +++ /dev/null @@ -1,20 +0,0 @@ -package pronghorn.handlers - -import com.jsoniter.output.JsonStream -import pronghorn.utils.JsonSupport -import tech.pronghorn.http.* -import tech.pronghorn.http.protocol.CommonContentTypes -import tech.pronghorn.server.requesthandlers.DirectHttpRequestHandler -import java.io.ByteArrayOutputStream - -data class JsonExample(val message: String) - -class JsonHandler: DirectHttpRequestHandler(), JsonSupport { - override val outputStream = ByteArrayOutputStream() - override val stream = JsonStream(outputStream, 32) - - override fun handleDirect(exchange: HttpExchange): HttpResponse { - val example = JsonExample("Hello, World!") - return HttpResponses.OK(toJson(example), CommonContentTypes.ApplicationJson) - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestFortunesHandler.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestFortunesHandler.kt deleted file mode 100644 index a8ed9729511..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestFortunesHandler.kt +++ /dev/null @@ -1,24 +0,0 @@ -package pronghorn.handlers - -import httl.Engine -import pronghorn.types.Fortune -import pronghorn.utils.MongoDBHandlerHelpers -import tech.pronghorn.http.* -import tech.pronghorn.http.protocol.CommonContentTypes -import tech.pronghorn.server.HttpServerWorker -import java.io.ByteArrayOutputStream - -class MongoDBRequestFortunesHandler(worker: HttpServerWorker) : MongoDBHandlerHelpers(worker) { - private val collection = getFortunesCollection() - private val engine = Engine.getEngine() - private val template = engine.getTemplate("/fortunes.httl") - private val output = ByteArrayOutputStream() - - suspend override fun handle(exchange: HttpExchange): HttpResponse { - val fortunes = findFortunes(collection) - fortunes.add(Fortune(0, "Additional fortune added at request time.")) - output.reset() - template.render(mapOf("fortunes" to fortunes), output) - return HttpResponses.OK(output.toByteArray(), CommonContentTypes.TextHtml, Charsets.UTF_8) - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestMultiHandler.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestMultiHandler.kt deleted file mode 100644 index 347f02bde20..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestMultiHandler.kt +++ /dev/null @@ -1,22 +0,0 @@ -package pronghorn.handlers - -import pronghorn.types.World -import pronghorn.utils.JsonSupport -import pronghorn.utils.MongoDBHandlerHelpers -import tech.pronghorn.coroutines.awaitable.InternalFuture -import tech.pronghorn.coroutines.awaitable.await -import tech.pronghorn.http.* -import tech.pronghorn.http.protocol.CommonContentTypes -import tech.pronghorn.server.HttpServerWorker - -class MongoDBRequestMultiHandler(worker: HttpServerWorker) : MongoDBHandlerHelpers(worker), JsonSupport { - private val collection = getWorldCollection() - - suspend override fun handle(exchange: HttpExchange): HttpResponse { - val future = InternalFuture>() - val worldCount = getQueryCount(exchange) - findWorlds(collection, future.promise(), worldCount) - val results = await(future) - return HttpResponses.OK(toJson(results), CommonContentTypes.ApplicationJson) - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestSingleHandler.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestSingleHandler.kt deleted file mode 100644 index 2aaaca95a1e..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestSingleHandler.kt +++ /dev/null @@ -1,15 +0,0 @@ -package pronghorn.handlers - -import pronghorn.utils.MongoDBHandlerHelpers -import tech.pronghorn.http.* -import tech.pronghorn.http.protocol.CommonContentTypes -import tech.pronghorn.server.HttpServerWorker - -class MongoDBRequestSingleHandler(worker: HttpServerWorker) : MongoDBHandlerHelpers(worker) { - private val collection = getWorldCollection() - - suspend override fun handle(exchange: HttpExchange): HttpResponse { - val world = findWorld(collection) - return HttpResponses.OK(toJson(world), CommonContentTypes.ApplicationJson) - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestUpdatesHandler.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestUpdatesHandler.kt deleted file mode 100644 index 24f6fc81b6a..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/handlers/MongoDBRequestUpdatesHandler.kt +++ /dev/null @@ -1,23 +0,0 @@ -package pronghorn.handlers - -import pronghorn.types.World -import pronghorn.utils.MongoDBHandlerHelpers -import tech.pronghorn.coroutines.awaitable.InternalFuture -import tech.pronghorn.coroutines.awaitable.await -import tech.pronghorn.http.* -import tech.pronghorn.http.protocol.CommonContentTypes -import tech.pronghorn.server.HttpServerWorker - -class MongoDBRequestUpdatesHandler(worker: HttpServerWorker) : MongoDBHandlerHelpers(worker) { - private val collection = getWorldCollection() - - suspend override fun handle(exchange: HttpExchange): HttpResponse { - val future = InternalFuture>() - val worldCount = getQueryCount(exchange) - findWorlds(collection, future.promise(), worldCount) - val results = await(future) - results.forEach { world -> world.randomNumber = random.nextInt(10000) + 1 } - writeWorlds(collection, results) - return HttpResponses.OK(toJson(results), CommonContentTypes.ApplicationJson) - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/Fortune.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/Fortune.kt deleted file mode 100644 index 8e1bfcb305b..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/Fortune.kt +++ /dev/null @@ -1,6 +0,0 @@ -package pronghorn.types - -class Fortune(val id: Int, - val message: String): Comparable { - override fun compareTo(other: Fortune): Int = message.compareTo(other.message) -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/World.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/World.kt deleted file mode 100644 index f97b500193b..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/World.kt +++ /dev/null @@ -1,4 +0,0 @@ -package pronghorn.types - -class World(val id: Int, - var randomNumber: Int) diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/codecs/FortuneCodec.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/codecs/FortuneCodec.kt deleted file mode 100644 index 4158ade8515..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/codecs/FortuneCodec.kt +++ /dev/null @@ -1,36 +0,0 @@ -package pronghorn.types.codecs - -import org.bson.* -import org.bson.codecs.* -import pronghorn.types.Fortune - -object FortuneCodec : Codec { - private val fortuneClass = Fortune::class.java - - override fun encode(writer: BsonWriter, value: Fortune, encoderContext: EncoderContext) { - writer.writeStartDocument() - writer.writeInt32(value.id) - writer.writeString(value.message) - writer.writeEndDocument() - } - - override fun getEncoderClass(): Class = fortuneClass - - override fun decode(reader: BsonReader, decoderContext: DecoderContext): Fortune { - reader.readStartDocument() - reader.readBsonType() - reader.skipName() - val id = when(reader.currentBsonType) { - BsonType.DOUBLE -> reader.readDouble().toInt() - BsonType.INT32 -> reader.readInt32() - else -> throw Exception("Unexpected ID Type") - } - reader.readBsonType() - reader.skipName() - reader.skipValue() - val message = reader.readString("message") - val fortune = Fortune(id, message) - reader.readEndDocument() - return fortune - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/codecs/WorldCodec.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/codecs/WorldCodec.kt deleted file mode 100644 index f3afaea46d1..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/types/codecs/WorldCodec.kt +++ /dev/null @@ -1,42 +0,0 @@ -package pronghorn.types.codecs - -import org.bson.* -import org.bson.codecs.* -import pronghorn.types.World - -object WorldCodec: Codec { - private val worldClass = World::class.java - - override fun encode(writer: BsonWriter, value: World, encoderContext: EncoderContext) { - writer.writeStartDocument() - writer.writeInt32(value.id) - writer.writeInt32(value.randomNumber) - writer.writeEndDocument() - } - - override fun getEncoderClass(): Class = worldClass - - override fun decode(reader: BsonReader, decoderContext: DecoderContext): World { - reader.readStartDocument() - reader.readBsonType() - reader.skipName() - val id = when(reader.currentBsonType) { - BsonType.DOUBLE -> reader.readDouble().toInt() - BsonType.INT32 -> reader.readInt32() - else -> throw Exception("Unexpected ID Type") - } - reader.readBsonType() - reader.skipName() - reader.skipValue() - reader.readBsonType() - reader.skipName() - val randomNumber = when(reader.currentBsonType) { - BsonType.DOUBLE -> reader.readDouble().toInt() - BsonType.INT32 -> reader.readInt32() - else -> throw Exception("Unexpected randomNumber Type") - } - val world = World(id, randomNumber) - reader.readEndDocument() - return world - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/JsonSupport.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/JsonSupport.kt deleted file mode 100644 index 157e5d1acc5..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/JsonSupport.kt +++ /dev/null @@ -1,16 +0,0 @@ -package pronghorn.utils - -import com.jsoniter.output.JsonStream -import java.io.ByteArrayOutputStream - -interface JsonSupport { - val outputStream: ByteArrayOutputStream - val stream: JsonStream - - fun toJson(any: Any): ByteArray { - outputStream.reset() - stream.writeVal(any) - stream.flush() - return outputStream.toByteArray() - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/LoggingUtils.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/LoggingUtils.kt deleted file mode 100644 index f00d800d5fd..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/LoggingUtils.kt +++ /dev/null @@ -1,11 +0,0 @@ -package pronghorn.utils - -import ch.qos.logback.classic.Level -import ch.qos.logback.classic.LoggerContext -import org.slf4j.LoggerFactory - -fun setLibraryLogging(level: Level) { - val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext - loggerContext.getLogger("org.mongodb.driver").level = level - loggerContext.getLogger("httl").level = level -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/MongoDBClientAttachmentKey.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/MongoDBClientAttachmentKey.kt deleted file mode 100644 index 3056c4d90e0..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/MongoDBClientAttachmentKey.kt +++ /dev/null @@ -1,6 +0,0 @@ -package pronghorn.utils - -import com.mongodb.async.client.MongoClient -import tech.pronghorn.coroutines.core.WorkerAttachmentKey - -object MongoDBClientAttachmentKey : WorkerAttachmentKey diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/MongoDBHandlerHelpers.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/MongoDBHandlerHelpers.kt deleted file mode 100644 index c4d3cff61e2..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/MongoDBHandlerHelpers.kt +++ /dev/null @@ -1,155 +0,0 @@ -package pronghorn.utils - -import com.jsoniter.output.JsonStream -import com.mongodb.ServerAddress -import com.mongodb.async.client.* -import com.mongodb.client.model.Filters -import com.mongodb.client.model.UpdateOneModel -import com.mongodb.connection.ClusterSettings -import com.mongodb.connection.ConnectionPoolSettings -import org.bson.Document -import org.bson.codecs.configuration.CodecRegistries -import pronghorn.types.Fortune -import pronghorn.types.World -import pronghorn.types.codecs.FortuneCodec -import pronghorn.types.codecs.WorldCodec -import tech.pronghorn.coroutines.awaitable.InternalFuture -import tech.pronghorn.coroutines.awaitable.await -import tech.pronghorn.http.HttpExchange -import tech.pronghorn.mongodb.MultiplexMongoDBStreamFactoryFactory -import tech.pronghorn.server.HttpServerWorker -import tech.pronghorn.server.requesthandlers.SuspendableHttpRequestHandler -import java.io.ByteArrayOutputStream -import java.util.SplittableRandom -import java.util.TreeSet - -private val queriesBytes = "queries".toByteArray(Charsets.US_ASCII) - -abstract class MongoDBHandlerHelpers(worker: HttpServerWorker) : SuspendableHttpRequestHandler(), JsonSupport { - private val mongoClient = worker.getOrPutAttachment(MongoDBClientAttachmentKey, { createMongoClient(worker) }) - protected val random = SplittableRandom() - override final val outputStream = ByteArrayOutputStream() - override final val stream = JsonStream(outputStream, 32) - - protected fun getWorldCollection(): MongoCollection { - return mongoClient - .getDatabase(TestConfig.dbName) - .getCollection(TestConfig.worldCollectionName) - .withDocumentClass(World::class.java) - } - - protected fun getFortunesCollection(): MongoCollection { - return mongoClient - .getDatabase(TestConfig.dbName) - .getCollection(TestConfig.fortunesCollectionName) - .withDocumentClass(Fortune::class.java) - } - - private fun createMongoClient(worker: HttpServerWorker): MongoClient { - val poolSettings = ConnectionPoolSettings.builder() - .minSize(1) - .maxSize(Int.MAX_VALUE) // connections are multiplexed via Pronghorn Stream, so max size is irrelevant - .maxWaitQueueSize(0) - .build() - - val clusterSettings = ClusterSettings.builder() - .hosts(listOf(ServerAddress(TestConfig.dbHost, TestConfig.dbPort))) - .build() - - val multiplexedFactory = MultiplexMongoDBStreamFactoryFactory(worker) - - val codecRegistry = CodecRegistries.fromRegistries( - MongoClients.getDefaultCodecRegistry(), - CodecRegistries.fromCodecs(FortuneCodec, WorldCodec) - ) - - val settings = MongoClientSettings.builder() - .clusterSettings(clusterSettings) - .connectionPoolSettings(poolSettings) - .streamFactoryFactory(multiplexedFactory) - .codecRegistry(codecRegistry) - .build() - - val client = MongoClients.create(settings) - worker.registerShutdownMethod { - client.close() - } - return client - } - - protected fun getQueryCount(exchange: HttpExchange): Int { - return Math.max(1, Math.min(500, exchange.requestUrl.getQueryParamAsInt(queriesBytes) ?: 1)) - } - - suspend protected fun findWorld(collection: MongoCollection): World { - val future = InternalFuture() - val promise = future.promise() - val id = random.nextInt(10000) + 1 - collection.find(Document("_id", id)).first { world, ex -> - when { - world != null -> promise.complete(world) - ex != null -> promise.completeExceptionally(ex) - else -> promise.completeExceptionally(Exception("Missing document.")) - } - } - return await(future) - } - - @Suppress("UNCHECKED_CAST") - protected fun findWorlds(collection: MongoCollection, - promise: InternalFuture.InternalPromise>, - count: Int, - results: Array = arrayOfNulls(count)) { - val id = count - val searchDocument = Document("_id", id) - collection.find(searchDocument).first { world, ex -> - when { - world != null -> { - results[count - 1] = world - if (count == 1) { - promise.complete(results as Array) - } - else { - findWorlds(collection, promise, count - 1, results) - } - } - ex != null -> promise.completeExceptionally(ex) - else -> promise.completeExceptionally(Exception("Missing document.")) - } - } - } - - protected suspend fun findFortunes(collection: MongoCollection): TreeSet { - val future = InternalFuture() - val promise = future.promise() - val fortunes = TreeSet() - - collection.find().into(fortunes, { _, _ -> promise.complete(Unit) }) - - await(future) - return fortunes - } - - protected suspend fun writeWorlds(collection: MongoCollection, - results: Array) { - val updateFuture = InternalFuture() - val updatePromise = updateFuture.promise() - - val updates = results.map { result -> - UpdateOneModel( - Filters.eq("_id", result.id), - Document("\$set", Document("randomNumber", result.randomNumber)) - ) - } - - collection.bulkWrite(updates, { result, ex -> - when { - result != null -> updatePromise.complete(Unit) - ex != null -> updatePromise.completeExceptionally(ex) - else -> updatePromise.completeExceptionally(Exception("Unexpected update failure.")) - } - }) - - await(updateFuture) - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/TestConfig.kt b/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/TestConfig.kt deleted file mode 100644 index 09ef4fdeefd..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/kotlin/pronghorn/utils/TestConfig.kt +++ /dev/null @@ -1,35 +0,0 @@ -package pronghorn.utils - -import tech.pronghorn.util.ignoreException -import java.util.Properties - -object TestConfig { - private val properties = parsePropertiesConfig() - val listenHost = properties.getProperty("listenHost", "0.0.0.0") - val listenPort = getIntProperty("listenPort", 8080) - val dbHost = properties.getProperty("dbHost", "tfb-database") - val dbPort = getIntProperty("dbPort", 27017) - val dbName = properties.getProperty("dbName", "hello_world") - val fortunesCollectionName = properties.getProperty("fortunesCollectionName", "fortune") - val worldCollectionName = properties.getProperty("worldCollectionName", "world") - - private fun getIntProperty(key: String, - default: Int): Int { - val result = properties.getProperty(key) - return when (result) { - null -> default - else -> result.toIntOrNull() ?: default - } - } - - private fun parsePropertiesConfig(): Properties { - val properties = Properties() - ignoreException { - val stream = javaClass.classLoader.getResource("benchmark.properties")?.openStream() - if (stream != null) { - properties.load(stream) - } - } - return properties - } -} diff --git a/frameworks/Kotlin/pronghorn/src/main/resources/benchmark.properties b/frameworks/Kotlin/pronghorn/src/main/resources/benchmark.properties deleted file mode 100644 index 0e62ae9b53c..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/resources/benchmark.properties +++ /dev/null @@ -1,7 +0,0 @@ -listenHost=0.0.0.0 -listenPort=8080 -dbHost=tfb-database -dbPort=27017 -dbName=hello_world -fortunesCollectionName=fortune -worldCollectionName=world diff --git a/frameworks/Kotlin/pronghorn/src/main/resources/fortunes.httl b/frameworks/Kotlin/pronghorn/src/main/resources/fortunes.httl deleted file mode 100644 index de8d01ae0e9..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/resources/fortunes.httl +++ /dev/null @@ -1 +0,0 @@ -Fortunes
idmessage
${fortune.id}${fortune.message}
diff --git a/frameworks/Kotlin/pronghorn/src/main/resources/httl.properties b/frameworks/Kotlin/pronghorn/src/main/resources/httl.properties deleted file mode 100644 index 33cd652a032..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/resources/httl.properties +++ /dev/null @@ -1,5 +0,0 @@ -import.packages+=pronghorn.types -input.encoding=UTF-8 -output.encoding=UTF-8 -reloadable=false -precompiled=false diff --git a/frameworks/Kotlin/pronghorn/src/main/resources/logback.xml b/frameworks/Kotlin/pronghorn/src/main/resources/logback.xml deleted file mode 100644 index f8a0bcedfc3..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/resources/logback.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - diff --git a/frameworks/Kotlin/pronghorn/src/main/resources/pronghorn.properties b/frameworks/Kotlin/pronghorn/src/main/resources/pronghorn.properties deleted file mode 100644 index 030160c0a3c..00000000000 --- a/frameworks/Kotlin/pronghorn/src/main/resources/pronghorn.properties +++ /dev/null @@ -1,6 +0,0 @@ -pronghorn.plugins.LoggingPlugin = tech.pronghorn.plugins.Slf4jLoggingPlugin -pronghorn.plugins.SpscQueuePlugin = tech.pronghorn.plugins.JCToolsSpscQueuePlugin -pronghorn.plugins.MpscQueuePlugin = tech.pronghorn.plugins.JCToolsMpscQueuePlugin -pronghorn.plugins.ConcurrentMapPlugin = tech.pronghorn.plugins.JCToolsConcurrentMapPlugin -pronghorn.plugins.ConcurrentSetPlugin = tech.pronghorn.plugins.JCToolsConcurrentSetPlugin -pronghorn.plugins.ArrayHasherPlugin = tech.pronghorn.plugins.OpenHFTArrayHasherPlugin