SlideShare a Scribd company logo
with Scala and Swift
Markus Jura
A high performance,
open-source universal RPC framework
WAIT
REMOTE PROCEDURE
CALLS
NOT AGAIN
CORBA HELLO WORLD
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;
class HelloImpl extends HelloPOA {
private ORB orb;
public void setORB(ORB orb_val) {
orb = orb_val;
}
// implement sayHello() method
public String sayHello() {
return "nHello world !!n";
}
// implement shutdown() method
public void shutdown() {
orb.shutdown(false);
}
}
public class HelloServer {
public static void main(String args[]) {
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get reference to rootpoa & activate the POAManager
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
// create servant and register it with the ORB
HelloImpl helloImpl = new HelloImpl();
helloImpl.setORB(orb);
// get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl);
Hello href = HelloHelper.narrow(ref);
// get the root naming context
// NameService invokes the name service
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
// Use NamingContextExt which is part of the Interoperable
// Naming Service (INS) specification.
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
// bind the Object Reference in Naming
String name = "Hello";
NameComponent path[] = ncRef.to_name( name );
ncRef.rebind(path, href);
System.out.println("HelloServer ready and waiting ...");
// wait for invocations from clients
orb.run();
}
catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
System.out.println("HelloServer Exiting ...");
}
}
SOAP HELLO WORLD
HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: text/xml;charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net.
RI's version is JAX-WS RI 2.1.1 in JDK 6. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net.
RI's version is JAX-WS RI 2.1.1 in JDK 6. -->
<definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.mkyong.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://ws.mkyong.com/"
name="HelloWorldImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.mkyong.com/"
schemaLocation="http://localhost:9999/ws/hello?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="getHelloWorldAsString">
<part name="parameters" element="tns:getHelloWorldAsString"></part>
</message>
<message name="getHelloWorldAsStringResponse">
<part name="parameters" element="tns:getHelloWorldAsStringResponse"></part>
</message>
<portType name="HelloWorld">
<operation name="getHelloWorldAsString">
<input message="tns:getHelloWorldAsString"></input>
<output message="tns:getHelloWorldAsStringResponse"></output>
</operation>
</portType>
<binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document">
</soap:binding>
<operation name="getHelloWorldAsString">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="HelloWorldImplService">
<port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
<soap:address location="http://localhost:9999/ws/hello"></soap:address>
</port>
</service>
</definitions>
GRPC HELLO WORLD
// Service definition
service Greeter {
rpc SayHello(HelloRequest) returns (HelloReply) {}
}
// Service implementation
override def sayHello(request: HelloRequest): Future[HelloReply] =
Future.successful(HelloReply(s"Hello ${request.name}"))
OVERVIEW
▪ Open source
▪ Developed by Google and Square
▪ HTTP/2
▪ Service and schema definition in protobuf
▪ Protobuf binary serialization
▪ Source code generation
HOW DOES IT WORK
Gateway Backend
gRPC
Impl
gRPC
Stub
gRPC
Stub
gRPC
Impl
SUPPORTED LANGUAGES
C++ Java Python
Go
Ruby
C#
Objective-C
Node.js
PHP
Android Java
Official support
Community support Scala
Kotlin
Swift
More
Haskell
BENEFITS
Streaming
PerformanceSimplicity
Interoperability
Reduced Network
Traffic
Consistency
IN THE REAL WORLD
GRPC IN ACTION
DEPENDENCIES PLUGINS.SBT
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.12")
libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.6.6"
DEPENDENCIES BUILD.SBT
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
lazy val scalaPbVersion = com.trueaccord.scalapb.compiler.Version.scalapbVersion
libraryDependencies ++= Seq(
"io.grpc" % "grpc-netty" % scalaPbVersion,
"com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % scalaPbVersion
)
REQUEST-RESPONSE PATTERN
Passenger ServiceSynchronous
Non-blocking
DEMO
SERVER-PUSH PATTERN
Passenger Service
1. Initiate connection
Non-blocking
2. Push data frames
3. Close connection
DEMO
CLIENT-PUSH PATTERN
Passenger Service
1. Initiate connection
Non-blocking
2. Push data frames
3. Close connection
BI-DIRECTIONAL STREAMING PATTERN
Passenger Service
1. Initiate connection
Non-blocking
2. Push data frames
3. Close connection
DEMO
PERFORMANCE
PERFORMANCE BENCHMARK
# of requests # of clients total time per-request time
jsonrpc 300.000 1 8m 7s 1.6ms
gRPC 300.000 1 37s 0.12ms
gRPC 300.000 100 7s 0.02ms
▪ Requests on single TCP connection
▪ jsonrpc: HTTP/1.1 JSON
▪ gRPC: HTTP/2.0 Protobuf
https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/
PERFORMANCE BENCHMARK
jsonrpc gRPC delta
NSPerOp 487.271.046.903 36.716.116.701 -92,46 %
AllocsPerOp 32.747.687 25.221.256 -22,98 %
AllocedBytesPerOp 3.182.814.152 1.795.122.672 -43,60 %
▪ CPU and memory usage on single TCP connection
▪ jsonrpc: HTTP/1.1 JSON
▪ gRPC: HTTP/2.0 Protobuf
https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/
PERFORMANCE BENCHMARK
gRPC gRPC with 100 clients delta
NSPerOp 36.716.116.701 7.168.591.678 -80,48 %
AllocsPerOp 25.221.256 25.221.256 +0.04%
AllocedBytesPerOp 1.795.122.672 1.795.122.672 +0.04%
CPU and memory usage: 1 gRPC client vs. 100 gRPC clients
https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/
BEST PRACTICES
WITHOUT PRIMITIVE WRAPPERS
syntax = "proto3";
package io.moia;
message BookingRequest {
string userId = 1;
int32 passengers = 2;
Address pickupAddress = 3;
}
final case class BookingRequest(
userId: String = "",
passengers: Int = 0,
pickupAddress: scala.Option[io.moia.passenger.Address] = None
) extends com.trueaccord.scalapb.GeneratedMessage with ...
passenger.proto
BookingRequest.scala
DEFAULT VALUES
▪ All fields are optional in proto3
▪ Missing fields are set to their default value
▪ string: ""
▪ numbers: 0
▪ boolean: false
WITH PRIMITIVE WRAPPERS
import "google/protobuf/wrappers.proto";
message BookingRequest {
google.protobuf.StringValue userId = 1;
google.protobuf.Int32Value passengers = 2;
Address pickupAddress = 3;
}
final case class BookingRequest(
userId: scala.Option[String] = None,
passengers: scala.Option[Int] = None,
pickupAddress: scala.Option[io.moia.passenger.Address] = None
) extends com.trueaccord.scalapb.GeneratedMessage with ...
passenger.proto
BookingRequest.scala
SHARING PROTOBUF DEFINITIONS
▪ Separate code repository for Protobuf definitions
▪ Publish generated files per language to package manager
▪ Use packages as dependency on client and server
=> One source of truth
=> Clean versioning
THERE IS MORE..
LINKS
▪ gRPC: grpc.io
▪ ScalaPB: scalapb.github.io
▪ grpc-java: github.com/grpc/grpc-java
▪ grpc-swift: github.com/grpc/grpc-swift
▪ Introduction to HTTP/2: developers.google.com/http2
▪ passenger-grpc example: github.com/moia-dev/passenger-grpc
CREDITS
▪ Google and Square
▪ ScalaPB
▪ Nadav Samet (trueaccord)
▪ Kenji Yoshida (xuwei-k)
▪ grpc-swift
▪ Tim Burks (timburks)
Q & OPTION[A]
gRPC with Scala and Swift

More Related Content

What's hot

On Centralizing Logs
On Centralizing LogsOn Centralizing Logs
On Centralizing Logs
Sematext Group, Inc.
 
How to cook lettuce @Java casual
How to cook lettuce @Java casualHow to cook lettuce @Java casual
How to cook lettuce @Java casual
Go Hagiwara
 
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
EPAM_Systems_Bulgaria
 
Embedded systems
Embedded systems Embedded systems
Embedded systems
Katy Anton
 
I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slow
aragozin
 
Java on Linux for devs and ops
Java on Linux for devs and opsJava on Linux for devs and ops
Java on Linux for devs and ops
aragozin
 
Varnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user groupVarnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user group
Jorge Nerín
 
Tuning Solr for Logs
Tuning Solr for LogsTuning Solr for Logs
Tuning Solr for Logs
Sematext Group, Inc.
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scriptingTony Fabeen
 
YASPS OPENNING
YASPS OPENNINGYASPS OPENNING
YASPS OPENNING
Jeen Lee
 
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
Alexey Lesovsky
 
nginx: writing your first module
nginx: writing your first modulenginx: writing your first module
nginx: writing your first moduleredivy
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
James Turnbull
 
MySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAsMySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAs
Sveta Smirnova
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with TsungNgoc Dao
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
Greg DeKoenigsberg
 
Managing MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona ToolkitManaging MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona Toolkit
Sveta Smirnova
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
Antony T Curtis
 
Performance tests with Gatling (extended)
Performance tests with Gatling (extended)Performance tests with Gatling (extended)
Performance tests with Gatling (extended)
Andrzej Ludwikowski
 

What's hot (20)

On Centralizing Logs
On Centralizing LogsOn Centralizing Logs
On Centralizing Logs
 
How to cook lettuce @Java casual
How to cook lettuce @Java casualHow to cook lettuce @Java casual
How to cook lettuce @Java casual
 
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
 
Embedded systems
Embedded systems Embedded systems
Embedded systems
 
I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slow
 
Java on Linux for devs and ops
Java on Linux for devs and opsJava on Linux for devs and ops
Java on Linux for devs and ops
 
Varnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user groupVarnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user group
 
Tuning Solr for Logs
Tuning Solr for LogsTuning Solr for Logs
Tuning Solr for Logs
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
YASPS OPENNING
YASPS OPENNINGYASPS OPENNING
YASPS OPENNING
 
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
 
nginx: writing your first module
nginx: writing your first modulenginx: writing your first module
nginx: writing your first module
 
My name is Trinidad
My name is TrinidadMy name is Trinidad
My name is Trinidad
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
 
MySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAsMySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAs
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with Tsung
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
Managing MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona ToolkitManaging MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona Toolkit
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
 
Performance tests with Gatling (extended)
Performance tests with Gatling (extended)Performance tests with Gatling (extended)
Performance tests with Gatling (extended)
 

Similar to gRPC with Scala and Swift

DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
Dongmin Yu
 
Oracle cluster installation with grid and iscsi
Oracle cluster  installation with grid and iscsiOracle cluster  installation with grid and iscsi
Oracle cluster installation with grid and iscsi
Chanaka Lasantha
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
NAVER D2
 
Oracle cluster installation with grid and nfs
Oracle cluster  installation with grid and nfsOracle cluster  installation with grid and nfs
Oracle cluster installation with grid and nfs
Chanaka Lasantha
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!
Guatemala User Group
 
Mitaka_IntroStarlink.pdf
Mitaka_IntroStarlink.pdfMitaka_IntroStarlink.pdf
Mitaka_IntroStarlink.pdf
robinsroy28
 
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
Takehito Tanabe
 
2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
양재동 코드랩
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6
양재동 코드랩
 
2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf
UtabeUtabe
 
Automating Your Workflow with Gulp.js - php[world] 2016
Automating Your Workflow with Gulp.js - php[world] 2016Automating Your Workflow with Gulp.js - php[world] 2016
Automating Your Workflow with Gulp.js - php[world] 2016
Colin O'Dell
 
Angular 1 + es6
Angular 1 + es6Angular 1 + es6
Angular 1 + es6
장현 한
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
Sylvain Wallez
 
PyCon 2016: Personalised emails with Spark and Python
PyCon 2016:  Personalised emails  with Spark and PythonPyCon 2016:  Personalised emails  with Spark and Python
PyCon 2016: Personalised emails with Spark and Python
Tomas Sirny
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
Eric Jain
 
Jlook web ui framework
Jlook web ui frameworkJlook web ui framework
Jlook web ui framework
HongSeong Jeon
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 

Similar to gRPC with Scala and Swift (20)

DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
Oracle cluster installation with grid and iscsi
Oracle cluster  installation with grid and iscsiOracle cluster  installation with grid and iscsi
Oracle cluster installation with grid and iscsi
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
 
Oracle cluster installation with grid and nfs
Oracle cluster  installation with grid and nfsOracle cluster  installation with grid and nfs
Oracle cluster installation with grid and nfs
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!
 
Mitaka_IntroStarlink.pdf
Mitaka_IntroStarlink.pdfMitaka_IntroStarlink.pdf
Mitaka_IntroStarlink.pdf
 
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
 
2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6
 
2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf
 
Automating Your Workflow with Gulp.js - php[world] 2016
Automating Your Workflow with Gulp.js - php[world] 2016Automating Your Workflow with Gulp.js - php[world] 2016
Automating Your Workflow with Gulp.js - php[world] 2016
 
Angular 1 + es6
Angular 1 + es6Angular 1 + es6
Angular 1 + es6
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
PyCon 2016: Personalised emails with Spark and Python
PyCon 2016:  Personalised emails  with Spark and PythonPyCon 2016:  Personalised emails  with Spark and Python
PyCon 2016: Personalised emails with Spark and Python
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
 
Jlook web ui framework
Jlook web ui frameworkJlook web ui framework
Jlook web ui framework
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 

More from Markus Jura

8 things I wish I knew when I started with Akka
8 things I wish I knew when I started with Akka8 things I wish I knew when I started with Akka
8 things I wish I knew when I started with Akka
Markus Jura
 
Managing an Akka Cluster on Kubernetes
Managing an Akka Cluster on KubernetesManaging an Akka Cluster on Kubernetes
Managing an Akka Cluster on Kubernetes
Markus Jura
 
CRDTs with Akka Distributed Data
CRDTs with Akka Distributed DataCRDTs with Akka Distributed Data
CRDTs with Akka Distributed Data
Markus Jura
 
Demo gods are (not) on our side
Demo gods are (not) on our sideDemo gods are (not) on our side
Demo gods are (not) on our side
Markus Jura
 
Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"
Markus Jura
 
Reactive reference architecture
Reactive reference architectureReactive reference architecture
Reactive reference architecture
Markus Jura
 

More from Markus Jura (6)

8 things I wish I knew when I started with Akka
8 things I wish I knew when I started with Akka8 things I wish I knew when I started with Akka
8 things I wish I knew when I started with Akka
 
Managing an Akka Cluster on Kubernetes
Managing an Akka Cluster on KubernetesManaging an Akka Cluster on Kubernetes
Managing an Akka Cluster on Kubernetes
 
CRDTs with Akka Distributed Data
CRDTs with Akka Distributed DataCRDTs with Akka Distributed Data
CRDTs with Akka Distributed Data
 
Demo gods are (not) on our side
Demo gods are (not) on our sideDemo gods are (not) on our side
Demo gods are (not) on our side
 
Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"
 
Reactive reference architecture
Reactive reference architectureReactive reference architecture
Reactive reference architecture
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

gRPC with Scala and Swift

  • 1. with Scala and Swift Markus Jura
  • 2. A high performance, open-source universal RPC framework
  • 4. CORBA HELLO WORLD import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; import java.util.Properties; class HelloImpl extends HelloPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } // implement sayHello() method public String sayHello() { return "nHello world !!n"; } // implement shutdown() method public void shutdown() { orb.shutdown(false); } } public class HelloServer { public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // create servant and register it with the ORB HelloImpl helloImpl = new HelloImpl(); helloImpl.setORB(orb); // get object reference from the servant org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl); Hello href = HelloHelper.narrow(ref); // get the root naming context // NameService invokes the name service org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt which is part of the Interoperable // Naming Service (INS) specification. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming String name = "Hello"; NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, href); System.out.println("HelloServer ready and waiting ..."); // wait for invocations from clients orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } System.out.println("HelloServer Exiting ..."); } }
  • 5. SOAP HELLO WORLD HTTP/1.1 200 OK Transfer-encoding: chunked Content-type: text/xml;charset=utf-8 <?xml version="1.0" encoding="UTF-8"?> <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. --> <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. --> <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.mkyong.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.mkyong.com/" name="HelloWorldImplService"> <types> <xsd:schema> <xsd:import namespace="http://ws.mkyong.com/" schemaLocation="http://localhost:9999/ws/hello?xsd=1"></xsd:import> </xsd:schema> </types> <message name="getHelloWorldAsString"> <part name="parameters" element="tns:getHelloWorldAsString"></part> </message> <message name="getHelloWorldAsStringResponse"> <part name="parameters" element="tns:getHelloWorldAsStringResponse"></part> </message> <portType name="HelloWorld"> <operation name="getHelloWorldAsString"> <input message="tns:getHelloWorldAsString"></input> <output message="tns:getHelloWorldAsStringResponse"></output> </operation> </portType> <binding name="HelloWorldImplPortBinding" type="tns:HelloWorld"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"> </soap:binding> <operation name="getHelloWorldAsString"> <soap:operation soapAction=""></soap:operation> <input> <soap:body use="literal"></soap:body> </input> <output> <soap:body use="literal"></soap:body> </output> </operation> </binding> <service name="HelloWorldImplService"> <port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding"> <soap:address location="http://localhost:9999/ws/hello"></soap:address> </port> </service> </definitions>
  • 6. GRPC HELLO WORLD // Service definition service Greeter { rpc SayHello(HelloRequest) returns (HelloReply) {} } // Service implementation override def sayHello(request: HelloRequest): Future[HelloReply] = Future.successful(HelloReply(s"Hello ${request.name}"))
  • 7. OVERVIEW ▪ Open source ▪ Developed by Google and Square ▪ HTTP/2 ▪ Service and schema definition in protobuf ▪ Protobuf binary serialization ▪ Source code generation
  • 8. HOW DOES IT WORK Gateway Backend gRPC Impl gRPC Stub gRPC Stub gRPC Impl
  • 9. SUPPORTED LANGUAGES C++ Java Python Go Ruby C# Objective-C Node.js PHP Android Java Official support Community support Scala Kotlin Swift More Haskell
  • 11. IN THE REAL WORLD
  • 13. DEPENDENCIES PLUGINS.SBT addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.12") libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.6.6"
  • 14. DEPENDENCIES BUILD.SBT PB.targets in Compile := Seq( scalapb.gen() -> (sourceManaged in Compile).value ) lazy val scalaPbVersion = com.trueaccord.scalapb.compiler.Version.scalapbVersion libraryDependencies ++= Seq( "io.grpc" % "grpc-netty" % scalaPbVersion, "com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % scalaPbVersion )
  • 16. DEMO
  • 17. SERVER-PUSH PATTERN Passenger Service 1. Initiate connection Non-blocking 2. Push data frames 3. Close connection
  • 18. DEMO
  • 19. CLIENT-PUSH PATTERN Passenger Service 1. Initiate connection Non-blocking 2. Push data frames 3. Close connection
  • 20. BI-DIRECTIONAL STREAMING PATTERN Passenger Service 1. Initiate connection Non-blocking 2. Push data frames 3. Close connection
  • 21. DEMO
  • 23. PERFORMANCE BENCHMARK # of requests # of clients total time per-request time jsonrpc 300.000 1 8m 7s 1.6ms gRPC 300.000 1 37s 0.12ms gRPC 300.000 100 7s 0.02ms ▪ Requests on single TCP connection ▪ jsonrpc: HTTP/1.1 JSON ▪ gRPC: HTTP/2.0 Protobuf https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/
  • 24. PERFORMANCE BENCHMARK jsonrpc gRPC delta NSPerOp 487.271.046.903 36.716.116.701 -92,46 % AllocsPerOp 32.747.687 25.221.256 -22,98 % AllocedBytesPerOp 3.182.814.152 1.795.122.672 -43,60 % ▪ CPU and memory usage on single TCP connection ▪ jsonrpc: HTTP/1.1 JSON ▪ gRPC: HTTP/2.0 Protobuf https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/
  • 25. PERFORMANCE BENCHMARK gRPC gRPC with 100 clients delta NSPerOp 36.716.116.701 7.168.591.678 -80,48 % AllocsPerOp 25.221.256 25.221.256 +0.04% AllocedBytesPerOp 1.795.122.672 1.795.122.672 +0.04% CPU and memory usage: 1 gRPC client vs. 100 gRPC clients https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/
  • 27. WITHOUT PRIMITIVE WRAPPERS syntax = "proto3"; package io.moia; message BookingRequest { string userId = 1; int32 passengers = 2; Address pickupAddress = 3; } final case class BookingRequest( userId: String = "", passengers: Int = 0, pickupAddress: scala.Option[io.moia.passenger.Address] = None ) extends com.trueaccord.scalapb.GeneratedMessage with ... passenger.proto BookingRequest.scala
  • 28. DEFAULT VALUES ▪ All fields are optional in proto3 ▪ Missing fields are set to their default value ▪ string: "" ▪ numbers: 0 ▪ boolean: false
  • 29. WITH PRIMITIVE WRAPPERS import "google/protobuf/wrappers.proto"; message BookingRequest { google.protobuf.StringValue userId = 1; google.protobuf.Int32Value passengers = 2; Address pickupAddress = 3; } final case class BookingRequest( userId: scala.Option[String] = None, passengers: scala.Option[Int] = None, pickupAddress: scala.Option[io.moia.passenger.Address] = None ) extends com.trueaccord.scalapb.GeneratedMessage with ... passenger.proto BookingRequest.scala
  • 30. SHARING PROTOBUF DEFINITIONS ▪ Separate code repository for Protobuf definitions ▪ Publish generated files per language to package manager ▪ Use packages as dependency on client and server => One source of truth => Clean versioning
  • 32. LINKS ▪ gRPC: grpc.io ▪ ScalaPB: scalapb.github.io ▪ grpc-java: github.com/grpc/grpc-java ▪ grpc-swift: github.com/grpc/grpc-swift ▪ Introduction to HTTP/2: developers.google.com/http2 ▪ passenger-grpc example: github.com/moia-dev/passenger-grpc
  • 33. CREDITS ▪ Google and Square ▪ ScalaPB ▪ Nadav Samet (trueaccord) ▪ Kenji Yoshida (xuwei-k) ▪ grpc-swift ▪ Tim Burks (timburks)