51
QBIT High speed WebSocket and REST

Qbit (Early slide deck): Java Microservices Lib

Embed Size (px)

Citation preview

Page 1: Qbit (Early slide deck): Java Microservices Lib

QBITHigh speed WebSocket and REST

Page 2: Qbit (Early slide deck): Java Microservices Lib

WHAT IS QBIT

• Queuing library that uses principles of mechanical sympathy but not disruptor

• It uses poor man’s disruptor, which is a linked transfer queue, and batching to limit thread handoff

Page 3: Qbit (Early slide deck): Java Microservices Lib

PERFORMANCE

FAST!

Page 4: Qbit (Early slide deck): Java Microservices Lib

NO REALLY FAST

It all starts with a fast queue

Page 5: Qbit (Early slide deck): Java Microservices Lib

100M PING PONG

Page 6: Qbit (Early slide deck): Java Microservices Lib

100 M PING PONG

Page 7: Qbit (Early slide deck): Java Microservices Lib

QBIT

• QBit Overview 1

• library for services

• library not a platform or framework

• allows putting service behind a queue

• services are only accessed by one thread

• No thread sync is typically needed in services

Page 8: Qbit (Early slide deck): Java Microservices Lib

QBIT

• QBit Overview 2

• You can use QBit queues directly

• or you can create a service

• Embeddable (can work in Tomcat or Vertx or Spring Boot)

• Service is a Java class whose methods are executed via queues

Page 9: Qbit (Early slide deck): Java Microservices Lib

QBIT

• QBit Overview 3

• implements apartment model threading and is similar to Actors

• Does not use disruptor

• Uses regular Java Queues

• Fast 100 million ping pong calls per second

Page 10: Qbit (Early slide deck): Java Microservices Lib

QBIT

• QBit Overview 4

• Supports calling services via REST, and WebSocket

• Uses batching to reduce thread hand off to queues

• Items to be processed are collected and sent in batches not one at a time

• Batching reduces thread sync time and accessing shared variables (volatile)

Page 11: Qbit (Early slide deck): Java Microservices Lib

QBIT

Page 12: Qbit (Early slide deck): Java Microservices Lib

QBIT QUEUE EXAMPLE

Page 13: Qbit (Early slide deck): Java Microservices Lib

QBIT FLUSH/BATCH

• There is automatic flush support at some layers

• More is being added

• Flushing just means send a batch on the queue in this context

Page 14: Qbit (Early slide deck): Java Microservices Lib

QBIT SERVICE EXAMPLE

• TODO

• List

• Example

Page 15: Qbit (Early slide deck): Java Microservices Lib

QBIT TODO SERVICE

Page 16: Qbit (Early slide deck): Java Microservices Lib

TODO SERVICE CLASS

• Exposes service under URI `/todo-manager`

• exposes method list under `/todo-manager/list`

• exposes add under `/todo-manager/todo`

Page 17: Qbit (Early slide deck): Java Microservices Lib

SERVER CODE

Page 18: Qbit (Early slide deck): Java Microservices Lib
Page 19: Qbit (Early slide deck): Java Microservices Lib

SERVICE SERVER BUILDER

Page 20: Qbit (Early slide deck): Java Microservices Lib

SERVICE SERVER BUILDER

• ServiceServer Builder

• ServiceServer Builder builds a service server.

• `flushInterval` is how often you want it to flush queue batches

• `requestBatchSize` is how large you would like the batch to the queue

• `uri` is the root URI

• `pollTime` is a low level on how long you would it to park between queue polls

• More params will be exposed. (pipelining, HTTP compression, WebSocket buffer size)

Page 21: Qbit (Early slide deck): Java Microservices Lib

CLIENT CODE REST POST TODO ITEMS

Page 22: Qbit (Early slide deck): Java Microservices Lib

REST CLIENT CODE READ TODO ITEMS

Page 23: Qbit (Early slide deck): Java Microservices Lib

WEB SOCKET CLIENT

Page 24: Qbit (Early slide deck): Java Microservices Lib

YOU MAY HAVE NOTICED

• Lambda expression

• It uses a proxy interface

Page 25: Qbit (Early slide deck): Java Microservices Lib

WEB SOCKET CLIENT

• Needs builder like ServiceServer.

• ClientServiceBuilder will build ServiceClient

• Creates proxy

• Proxy allows async callbacks

Page 26: Qbit (Early slide deck): Java Microservices Lib

WEB SOCKET CLIENT PROXY INTERFACE

Page 27: Qbit (Early slide deck): Java Microservices Lib

CALL BACK

• Default Error handler

• Handles call

Page 28: Qbit (Early slide deck): Java Microservices Lib

QBIT DESIGNED TO BE PLUGGABLE

• QBit designed to be pluggable

• Could be used with Spring Boot or Spring MVC

• Can be used in Tomcat

• Can be used in Vertx

• Can be run standalone

• Can be run without web socket REST

Page 29: Qbit (Early slide deck): Java Microservices Lib

QBIT WORKS WITH ANY CLASS NO ANNOTATIONS NEEDED

Page 30: Qbit (Early slide deck): Java Microservices Lib

QBIT SERIES OF FACTORIES, INTERFACES AND BUILDERS ALLOW PLUG-ABILITY

Page 31: Qbit (Early slide deck): Java Microservices Lib

FACTORY SPI

• Discovery mechanism finds factories and implementations

Page 32: Qbit (Early slide deck): Java Microservices Lib

COMPLEX REST MAPPINGS

Page 33: Qbit (Early slide deck): Java Microservices Lib

INTERNALS

• Internals

• Service is a queue system for a service

• ServiceBundle is a collection of Services

• You can work with Service directly w/o a proxy

Page 34: Qbit (Early slide deck): Java Microservices Lib

EXAMPLE WORKING WITH SERVICE DIRECTLY

Page 35: Qbit (Early slide deck): Java Microservices Lib
Page 36: Qbit (Early slide deck): Java Microservices Lib

USING A SERVICE (INTERNAL)

Page 37: Qbit (Early slide deck): Java Microservices Lib

USING JSON FROM SERVICE (INTERNAL)

Page 38: Qbit (Early slide deck): Java Microservices Lib

USING JSON FROM SERVICE BUNDLE (INTERNAL)

Page 39: Qbit (Early slide deck): Java Microservices Lib

HTTP CLIENT FAST ASYNC PART OF QBIT

Page 40: Qbit (Early slide deck): Java Microservices Lib

HTTP REQUEST BUILDER

Page 41: Qbit (Early slide deck): Java Microservices Lib

HTTP CLIENT BUILDER

Page 42: Qbit (Early slide deck): Java Microservices Lib
Page 43: Qbit (Early slide deck): Java Microservices Lib

HTTP SERVER

Page 44: Qbit (Early slide deck): Java Microservices Lib

HTTP SERVER

• HTTP Server

• Implementations in Vertx and Netty

• Faster than Tomcat and Jetty (on benchmark tests I wrote)

• Faster than Vertx alone on some tests

Page 45: Qbit (Early slide deck): Java Microservices Lib

HTTP SERVER BUILDER

Page 46: Qbit (Early slide deck): Java Microservices Lib

USING CALLBACKS 1

Page 47: Qbit (Early slide deck): Java Microservices Lib

USING CALLBACKS 2

Page 48: Qbit (Early slide deck): Java Microservices Lib

USING CALLBACKS 3

Page 49: Qbit (Early slide deck): Java Microservices Lib

USING CALLBACKS 4

Page 50: Qbit (Early slide deck): Java Microservices Lib
Page 51: Qbit (Early slide deck): Java Microservices Lib

QBIT• Same techniques used in PE but generalized

• Benchmarks well against Tomcat, Jetty (4x faster than Tomcat, 2x faster than Jetty)

• Vertx vs. QBit mixed results (more tuning)

• Sometimes faster. Sometimes 15% slower.

• Not done. But more done than what PE uses

• QBit can run inside of Vertx easily.