qbit (early slide deck): java microservices lib
TRANSCRIPT
QBITHigh speed WebSocket and REST
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
PERFORMANCE
FAST!
NO REALLY FAST
It all starts with a fast queue
100M PING PONG
100 M PING PONG
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
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
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
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)
QBIT
QBIT QUEUE EXAMPLE
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
QBIT SERVICE EXAMPLE
• TODO
• List
• Example
QBIT TODO SERVICE
TODO SERVICE CLASS
• Exposes service under URI `/todo-manager`
• exposes method list under `/todo-manager/list`
• exposes add under `/todo-manager/todo`
SERVER CODE
SERVICE SERVER BUILDER
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)
CLIENT CODE REST POST TODO ITEMS
REST CLIENT CODE READ TODO ITEMS
WEB SOCKET CLIENT
YOU MAY HAVE NOTICED
• Lambda expression
• It uses a proxy interface
WEB SOCKET CLIENT
• Needs builder like ServiceServer.
• ClientServiceBuilder will build ServiceClient
• Creates proxy
• Proxy allows async callbacks
WEB SOCKET CLIENT PROXY INTERFACE
CALL BACK
• Default Error handler
• Handles call
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
QBIT WORKS WITH ANY CLASS NO ANNOTATIONS NEEDED
QBIT SERIES OF FACTORIES, INTERFACES AND BUILDERS ALLOW PLUG-ABILITY
FACTORY SPI
• Discovery mechanism finds factories and implementations
COMPLEX REST MAPPINGS
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
EXAMPLE WORKING WITH SERVICE DIRECTLY
USING A SERVICE (INTERNAL)
USING JSON FROM SERVICE (INTERNAL)
USING JSON FROM SERVICE BUNDLE (INTERNAL)
HTTP CLIENT FAST ASYNC PART OF QBIT
HTTP REQUEST BUILDER
HTTP CLIENT BUILDER
HTTP SERVER
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
HTTP SERVER BUILDER
USING CALLBACKS 1
USING CALLBACKS 2
USING CALLBACKS 3
USING CALLBACKS 4
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.