Skip to content

Commit

Permalink
[finagle-benchmark] rename thrift imports for clarity
Browse files Browse the repository at this point in the history
Problem:

ThriftJava/ThriftScala imports caused conflicts

Solution:

Use (and rename) more explicit imports

Differential Revision: https://phabricator.twitter.biz/D1027979
  • Loading branch information
mattdickinson5 authored and jenkins committed Dec 21, 2022
1 parent 35474eb commit 78a4599
Showing 1 changed file with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.twitter.finagle.thrift

import com.twitter.finagle.benchmark.StdBenchAnnotations
import com.twitter.finagle.benchmark.thriftjava
import com.twitter.finagle.benchmark.thriftscala
import scala.collection.JavaConverters._
import com.twitter.finagle.Service
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.finagle.benchmark.StdBenchAnnotations
import com.twitter.finagle.benchmark.thriftjava.{Request => TJavaRequest}
import com.twitter.finagle.benchmark.thriftjava.{Response => TJavaResponse}
import com.twitter.finagle.benchmark.thriftjava.{ThriftOneGenServer => TJavaThriftOneGenServer}
import com.twitter.finagle.benchmark.thriftscala.{Request => TScalaRequest}
import com.twitter.finagle.benchmark.thriftscala.{Response => TScalaResponse}
import com.twitter.finagle.benchmark.thriftscala.{ThriftOneGenServer => TScalaThriftOneGenServer}
import com.twitter.util.Await
import com.twitter.util.Future
import java.util.Arrays
import org.apache.thrift.protocol._
import org.apache.thrift.transport._
import org.openjdk.jmh.annotations._
import scala.collection.JavaConverters._

// bazel run //finagle/finagle-benchmark/src/main/scala:jmh -- 'ThriftGenBenchmark'
// bazel run //finagle/finagle-benchmark/src/main/scala:jmh -- 'ThriftGenBenchmark' -prof gc
Expand All @@ -23,17 +24,17 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
@Param(Array("0", "10", "100", "1000", "5000"))
var collectionSize: Int = _

var javaRequest: thriftjava.Request = _
var scalaRequest: thriftscala.Request = _
var javaRequest: TJavaRequest = _
var scalaRequest: TScalaRequest = _
var thriftRequestBytes: Array[Byte] = _
var javaServer: Service[Array[Byte], Array[Byte]] = _
var scalaServer: Service[Array[Byte], Array[Byte]] = _
var javaClient: thriftjava.ThriftOneGenServer.ServiceToClient = _
var scalaClient: thriftscala.ThriftOneGenServer.MethodPerEndpoint = _
var javaClient: TJavaThriftOneGenServer.ServiceToClient = _
var scalaClient: TScalaThriftOneGenServer.MethodPerEndpoint = _

@Setup
def setup() = {
javaRequest = new thriftjava.Request(
javaRequest = new TJavaRequest(
Int.MaxValue,
Long.MaxValue,
false,
Expand All @@ -42,7 +43,7 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
Map(new Integer(Int.MaxValue) -> "hello").asJava,
Seq.fill(collectionSize)(new java.lang.Long(Long.MaxValue)).toSet.asJava
)
scalaRequest = thriftscala.Request(
scalaRequest = TScalaRequest(
Int.MaxValue,
Long.MaxValue,
false,
Expand All @@ -63,15 +64,15 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
}
}
val scalaIface =
new thriftscala.ThriftOneGenServer.FinagledClient(echoScalaSvc, new TBinaryProtocol.Factory())
new TScalaThriftOneGenServer.FinagledClient(echoScalaSvc, new TBinaryProtocol.Factory())

// the mock service will throw an exception
try { Await.result(scalaIface.echo(scalaRequest)) }
catch { case _: Throwable => }

scalaServer = {
val impl = new thriftscala.ThriftOneGenServer.MethodPerEndpoint {
val scalaResponse = thriftscala.Response(
val impl = new TScalaThriftOneGenServer.MethodPerEndpoint {
val scalaResponse = TScalaResponse(
Int.MaxValue,
Long.MaxValue,
false,
Expand All @@ -80,13 +81,13 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
Map(Int.MaxValue -> "hello"),
Seq.fill(collectionSize)(Long.MaxValue).toSet
)
def echo(r: thriftscala.Request) = Future.value(scalaResponse)
def echo(r: TScalaRequest) = Future.value(scalaResponse)
}
new thriftscala.ThriftOneGenServer.FinagledService(impl, new TBinaryProtocol.Factory())
new TScalaThriftOneGenServer.FinagledService(impl, new TBinaryProtocol.Factory())
}
val thriftResponseBytes = Await.result(scalaServer(thriftRequestBytes))

scalaClient = new thriftscala.ThriftOneGenServer.FinagledClient(
scalaClient = new TScalaThriftOneGenServer.FinagledClient(
new Service[ThriftClientRequest, Array[Byte]] {
def apply(treq: ThriftClientRequest) = {
Future.value(thriftResponseBytes)
Expand All @@ -95,8 +96,8 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
new TBinaryProtocol.Factory())

javaServer = {
val impl = new thriftjava.ThriftOneGenServer.ServiceIface {
val javaResponse = new thriftjava.Response(
val impl = new TJavaThriftOneGenServer.ServiceIface {
val javaResponse = new TJavaResponse(
Int.MaxValue,
Long.MaxValue,
false,
Expand All @@ -105,12 +106,12 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
Map(new Integer(Int.MaxValue) -> "hello").asJava,
Seq.fill(collectionSize)(new java.lang.Long(Long.MaxValue)).toSet.asJava
)
def echo(r: thriftjava.Request) = Future.value(javaResponse)
def echo(r: TJavaRequest) = Future.value(javaResponse)
}
new thriftjava.ThriftOneGenServer.Service(impl, new TBinaryProtocol.Factory())
new TJavaThriftOneGenServer.Service(impl, new TBinaryProtocol.Factory())
}

javaClient = new thriftjava.ThriftOneGenServer.ServiceToClient(
javaClient = new TJavaThriftOneGenServer.ServiceToClient(
new Service[ThriftClientRequest, Array[Byte]] {
def apply(req: ThriftClientRequest) = Future.value(thriftResponseBytes)
},
Expand All @@ -123,7 +124,7 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
}

@Benchmark
def scala_client(): thriftscala.Response = {
def scala_client(): TScalaResponse = {
Await.result(scalaClient.echo(scalaRequest))
}

Expand All @@ -133,7 +134,7 @@ class ThriftGenBenchmark extends StdBenchAnnotations {
}

@Benchmark
def java_client(): thriftjava.Response = {
def java_client(): TJavaResponse = {
Await.result(javaClient.echo(javaRequest))
}
}

0 comments on commit 78a4599

Please sign in to comment.