Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24 from 47deg/UpgradeToNewHotness
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
juanpedromoreno authored Sep 18, 2018
2 parents b79414c + 0034728 commit 49b12c0
Show file tree
Hide file tree
Showing 31 changed files with 3,072 additions and 3,106 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: scala

scala:
- 2.12.3
- 2.12.6

jdk:
- oraclejdk8
Expand Down
187 changes: 93 additions & 94 deletions README.md

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions bench/src/main/scala/HttpBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,37 @@ package benchmark

import java.util.concurrent.TimeUnit

import metrifier.http.client.HttpClient
import cats.effect.IO
import metrifier.benchmark.Utils._
import metrifier.http.HttpConf
import metrifier.http.client.HttpClient
import metrifier.shared.model._
import Utils._
import org.http4s.client.blaze.PooledHttp1Client
import org.http4s.client.blaze.Http1Client
import org.openjdk.jmh.annotations._

import scalaz.concurrent.Task

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
class HttpBenchmark {

val client: HttpClient = new HttpClient(PooledHttp1Client(), HttpConf.host, HttpConf.port)
val client = new HttpClient(Http1Client[IO]().unsafeRunSync(), HttpConf.host, HttpConf.port)

@Benchmark
def listPersons: PersonList = client.listPersons.unsafePerformSync
def listPersons: PersonList = client.listPersons.unsafeRunSync()

@Benchmark
def getPerson: Person = client.getPerson(PersonId("1")).unsafePerformSync
def getPerson: Person = client.getPerson(PersonId("1")).unsafeRunSync()

@Benchmark
def getPersonLinks: PersonLinkList = client.getPersonLinks(PersonId("1")).unsafePerformSync
def getPersonLinks: PersonLinkList = client.getPersonLinks(PersonId("1")).unsafeRunSync()

@Benchmark
def createPerson: Person = mkPerson.unsafePerformSync
def createPerson: Person = mkPerson.unsafeRunSync()

@Benchmark
def programComposition: PersonAggregation = {

val aggregation: Task[PersonAggregation] = for {
val aggregation: IO[PersonAggregation] = for {
personList <- client.listPersons
p1 <- client.getPerson(PersonId("1"))
p2 <- client.getPerson(PersonId("2"))
Expand All @@ -45,7 +44,7 @@ class HttpBenchmark {
pNew <- mkPerson
} yield (p1, p2, p3, p4, p1Links, p3Links, personList.add(pNew))

aggregation.unsafePerformSync
aggregation.unsafeRunSync()
}

private[this] def mkPerson =
Expand All @@ -64,4 +63,7 @@ class HttpBenchmark {
pictureMedium = person.picture map (_.medium),
pictureThumbnail = person.picture map (_.thumbnail)
)

@TearDown
def stopClient(): Unit = client.shutdown()
}
27 changes: 12 additions & 15 deletions bench/src/main/scala/RPCAvroBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
package metrifier
package benchmark

import cats.effect.IO
import freestyle.rpc.protocol.Empty
import java.util.concurrent.TimeUnit

import metrifier.benchmark.Utils._
import metrifier.rpc.client.implicits._
import metrifier.rpc.protocols.{EmptyAvro, PersonServiceAvro}
import metrifier.rpc.protocols._
import metrifier.shared.model._
import Utils._
import monix.eval.Task
import org.openjdk.jmh.annotations._

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
class RPCAvroBenchmark {

val client: PersonServiceAvro.Client[Task] = implicitly[PersonServiceAvro.Client[Task]]
val client: PersonServiceAvro.Client[IO] = implicitly[PersonServiceAvro.Client[IO]]

@Benchmark
def listPersons: PersonList = client.listPersons(EmptyAvro()).runAsync.runF
def listPersons: PersonList = client.listPersons(Empty).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def getPerson: Person = client.getPerson(PersonId("1")).runAsync.runF
def getPerson: Person = client.getPerson(PersonId("1")).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def getPersonLinks: PersonLinkList =
client.getPersonLinks(PersonId("1")).runAsync.runF
client.getPersonLinks(PersonId("1")).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def createPerson: Person =
client
.createPerson(person)
.runAsync
.runF
client.createPerson(person).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def programComposition: PersonAggregation = {

def clientProgram: Task[PersonAggregation] = {
def clientProgram: IO[PersonAggregation] = {
for {
personList <- client.listPersons(EmptyAvro())
personList <- client.listPersons(Empty)
p1 <- client.getPerson(PersonId("1"))
p2 <- client.getPerson(PersonId("2"))
p3 <- client.getPerson(PersonId("3"))
Expand All @@ -50,7 +47,7 @@ class RPCAvroBenchmark {
} yield (p1, p2, p3, p4, p1Links, p3Links, personList.add(pNew))
}

clientProgram.runAsync.runF
clientProgram.unsafeRunTimed(defaultTimeOut).get
}

}
32 changes: 14 additions & 18 deletions bench/src/main/scala/RPCProtoBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
package metrifier
package benchmark

import org.openjdk.jmh.annotations._
import metrifier.shared.model._
import metrifier.rpc.client.implicits._
import java.util.concurrent.TimeUnit

import cats.effect.IO
import freestyle.rpc.protocol.Empty
import java.util.concurrent.TimeUnit
import metrifier.benchmark.Utils._
import metrifier.rpc.client.implicits._
import metrifier.rpc.protocols.PersonServicePB
import Utils._
import monix.eval.Task
import metrifier.shared.model._
import org.openjdk.jmh.annotations._

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
class RPCProtoBenchmark {

val client: PersonServicePB.Client[Task] = implicitly[PersonServicePB.Client[Task]]
val client: PersonServicePB.Client[IO] = implicitly[PersonServicePB.Client[IO]]

@Benchmark
def listPersons: PersonList = client.listPersons(Empty()).runAsync.runF
def listPersons: PersonList = client.listPersons(Empty).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def getPerson: Person = client.getPerson(PersonId("1")).runAsync.runF
def getPerson: Person = client.getPerson(PersonId("1")).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def getPersonLinks: PersonLinkList =
client.getPersonLinks(PersonId("1")).runAsync.runF
client.getPersonLinks(PersonId("1")).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def createPerson: Person =
client
.createPerson(person)
.runAsync
.runF
client.createPerson(person).unsafeRunTimed(defaultTimeOut).get

@Benchmark
def programComposition: PersonAggregation = {

def clientProgram: Task[PersonAggregation] = {
def clientProgram: IO[PersonAggregation] = {
for {
personList <- client.listPersons(Empty())
personList <- client.listPersons(Empty)
p1 <- client.getPerson(PersonId("1"))
p2 <- client.getPerson(PersonId("2"))
p3 <- client.getPerson(PersonId("3"))
Expand All @@ -51,7 +47,7 @@ class RPCProtoBenchmark {
} yield (p1, p2, p3, p4, p1Links, p3Links, personList.add(pNew))
}

clientProgram.runAsync.runF
clientProgram.unsafeRunTimed(defaultTimeOut).get
}

}
8 changes: 0 additions & 8 deletions bench/src/main/scala/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package metrifier
package benchmark

import metrifier.shared.model._

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}

object Utils {

Expand All @@ -22,10 +20,4 @@ object Utils {
email = "[email protected]",
picture = None
)

implicit class FutureOps[A](f: Future[A]) {

def runF: A = Await.result(f, defaultTimeOut)

}
}
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lazy val http = project
.aggregate(shared)
.settings(moduleName := "http")
.settings(name := n(moduleName.value))
.settings(commonSettings: _*)
.settings(libraryDependencies ++= httpDependencies)

lazy val `frees-rpc` = project
Expand All @@ -17,6 +18,7 @@ lazy val `frees-rpc` = project
.aggregate(shared)
.settings(moduleName := "frees-rpc")
.settings(name := n(moduleName.value))
.settings(commonSettings: _*)
.settings(libraryDependencies ++= rpcDependencies)
.settings(scalaMetaSettings: _*)

Expand All @@ -26,6 +28,7 @@ lazy val demo = project
.aggregate(http, `frees-rpc`)
.settings(moduleName := "demo")
.settings(name := n(moduleName.value))
.settings(commonSettings: _*)
.settings(scalaMetaSettings: _*)

lazy val bench = project
Expand All @@ -34,5 +37,6 @@ lazy val bench = project
.aggregate(http, `frees-rpc`)
.settings(moduleName := "bench")
.settings(name := n(moduleName.value))
.settings(commonSettings: _*)
.settings(scalaMetaSettings: _*)
.enablePlugins(JmhPlugin)
Binary file modified charts/chart-bar-gcp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified charts/chart-bar-local.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified charts/chart-radar-gcp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified charts/chart-radar-local.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 7 additions & 9 deletions demo/src/main/scala/HttpDemoApp.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package metrifier
package demo

import org.http4s.client.blaze.PooledHttp1Client
import metrifier.http.client._
import metrifier.http.codecs._
import cats.effect.IO
import metrifier.demo.Utils._
import metrifier.http.HttpConf
import metrifier.http.client._
import metrifier.shared.model._
import Utils._

import scalaz.concurrent.Task
import org.http4s.client.blaze.Http1Client

object HttpDemoApp {

def main(args: Array[String]): Unit = {

val client = new HttpClient(PooledHttp1Client(), HttpConf.host, HttpConf.port)
val client = new HttpClient(Http1Client[IO]().unsafeRunSync(), HttpConf.host, HttpConf.port)

val aggregation: Task[PersonAggregation] = for {
val aggregation: IO[PersonAggregation] = for {
personList <- client.listPersons
p1 <- client.getPerson(PersonId("1"))
p2 <- client.getPerson(PersonId("2"))
Expand All @@ -41,7 +39,7 @@ object HttpDemoApp {
)
} yield (p1, p2, p3, p4, p1Links, p3Links, personList.add(pNew))

val result: PersonAggregation = aggregation.unsafePerformSync
val result: PersonAggregation = aggregation.unsafeRunSync()

println(s"Result = $result")

Expand Down
21 changes: 9 additions & 12 deletions demo/src/main/scala/RPCAvroDemoApp.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package metrifier
package demo

import metrifier.shared.model._
import cats.effect.IO
import freestyle.rpc.protocol.Empty
import metrifier.demo.Utils._
import metrifier.rpc.client.implicits._
import metrifier.rpc.protocols._
import Utils._
import monix.eval.Task

import scala.concurrent.Await
import scala.concurrent.duration._
import metrifier.rpc.protocols.PersonServiceAvro
import metrifier.shared.model._

object RPCAvroDemoApp {

def clientProgram(implicit client: PersonServiceAvro.Client[Task]): Task[PersonAggregation] = {

def clientProgram(implicit client: PersonServiceAvro.Client[IO]): IO[PersonAggregation] = {
for {
personList <- client.listPersons(EmptyAvro())
personList <- client.listPersons(Empty)
p1 <- client.getPerson(PersonId("1"))
p2 <- client.getPerson(PersonId("2"))
p3 <- client.getPerson(PersonId("3"))
p4 <- client.getPerson(PersonId("4"))
p1Links <- client.getPersonLinks(PersonId(p1.id))
p3Links <- client.getPersonLinks(PersonId(p3.id))
pNew <- client.createPerson(person)
pNew <- client.createPerson(person)
} yield (p1, p2, p3, p4, p1Links, p3Links, personList.add(pNew))
}

def main(args: Array[String]): Unit = {

val result: PersonAggregation =
Await.result(clientProgram.runAsync, Duration.Inf)
clientProgram.unsafeRunSync()

println(s"Result = $result")

Expand Down
17 changes: 7 additions & 10 deletions demo/src/main/scala/RPCProtoDemoApp.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package metrifier
package demo

import cats.effect.IO
import freestyle.rpc.protocol.Empty
import metrifier.shared.model._
import metrifier.demo.Utils._
import metrifier.rpc.client.implicits._
import metrifier.rpc.protocols.PersonServicePB
import Utils._
import monix.eval.Task

import scala.concurrent.Await
import scala.concurrent.duration._
import metrifier.shared.model._

object RPCProtoDemoApp {

def clientProgram(implicit client: PersonServicePB.Client[Task]): Task[PersonAggregation] = {
def clientProgram(implicit client: PersonServicePB.Client[IO]): IO[PersonAggregation] = {
for {
personList <- client.listPersons(Empty())
personList <- client.listPersons(Empty)
p1 <- client.getPerson(PersonId("1"))
p2 <- client.getPerson(PersonId("2"))
p3 <- client.getPerson(PersonId("3"))
p4 <- client.getPerson(PersonId("4"))
p1Links <- client.getPersonLinks(PersonId(p1.id))
p3Links <- client.getPersonLinks(PersonId(p3.id))
pNew <- client.createPerson(person)
pNew <- client.createPerson(person)
} yield (p1, p2, p3, p4, p1Links, p3Links, personList.add(pNew))
}

def main(args: Array[String]): Unit = {

val result: PersonAggregation =
Await.result(clientProgram.runAsync, Duration.Inf)
clientProgram.unsafeRunSync()

println(s"Result = $result")

Expand Down
2 changes: 1 addition & 1 deletion deploy/tmpl-vm.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resources:
boot: true
autoDelete: true
initializeParams:
sourceImage: {{ COMPUTE_URL_BASE }}projects/debian-cloud/global/images/family/debian-8
sourceImage: {{ COMPUTE_URL_BASE }}projects/debian-cloud/global/images/family/debian-9
networkInterfaces:
- network: {{ COMPUTE_URL_BASE }}projects/{{ env["project"] }}/global/networks/default
accessConfigs:
Expand Down
Loading

0 comments on commit 49b12c0

Please sign in to comment.