Download - Real World Enterprise Reactive Programming using Vert.x

Transcript
Page 1: Real World Enterprise Reactive Programming using Vert.x

Mariam Hakobyan, Sascha Möllering, Björn Stahl

Real World Enterprise Reactive Programming using Vert.x

| zanox AG

Page 2: Real World Enterprise Reactive Programming using Vert.x

TABLE OF CONTENTS

1.Introduction

2.The Beginning

3.How to start?

4.Best Practices

5.Architecture

6.Deployment

7.Vert.x module system

8.Integration with messaging system

Page 3: Real World Enterprise Reactive Programming using Vert.x

INTRODUCTION ZANOX

Europe‘s leading performance advertising network

Page 4: Real World Enterprise Reactive Programming using Vert.x

THE BEGINNING

Java Magazin 04.14: Vert.x im UnternehmenseinsatzEntwicklung und Betrieb von asynchronen Applikationen mit Vert.x in der Praxis

Page 5: Real World Enterprise Reactive Programming using Vert.x

THE BEGINNING

● New core system for zanox

● Requirements are pretty high (not negotiable):

●Low latency

●High throughput

●Reactive

●Fast

Page 6: Real World Enterprise Reactive Programming using Vert.x

THE BEGINNING

https://github.com/Mr-Steel/vertx_fatjar

Page 7: Real World Enterprise Reactive Programming using Vert.x

“Vert.x is a lightweight, high performance application

platform for the JVM that's designed for modern

mobile, web, and enterprise applications.”

Vert.x

WHAT IS VERT.X?

Page 8: Real World Enterprise Reactive Programming using Vert.x

WHAT IS VERT.X?

Polyglot

Page 9: Real World Enterprise Reactive Programming using Vert.x

WHAT IS A VERTICLE?

●Classes with an own Classloader

●operates Single Threaded

●executed by an Event Loop

Page 10: Real World Enterprise Reactive Programming using Vert.x

Event Loop Pool

Event Bus

V V V W W W

TAKE A LOOK INSIDE

Page 11: Real World Enterprise Reactive Programming using Vert.x

HOW TO START?

●mvn archetype:generate -

Dfilter=io.vertx: (do not forget the

colon!)

●generates structure for all languages (JS,

Ruby, Groovy, Python)

●maven pom is already set with relevant data

Page 12: Real World Enterprise Reactive Programming using Vert.x

HOW TO START?

Page 13: Real World Enterprise Reactive Programming using Vert.x

Lessons learned - Profiling

● Verticles and WorkerVerticles appear in different

subtrees

● Be careful with blaming, a lot of stuff is just waiting

● If you think a verticle is a bottleneck: start more

instances of this verticle

● Measure every change & compare results (yeah yeah -

but really - do it!)

Page 14: Real World Enterprise Reactive Programming using Vert.x

BEST PRACTICESStarter Verticle

Page 15: Real World Enterprise Reactive Programming using Vert.x

BEST PRACTICESLogging

Page 16: Real World Enterprise Reactive Programming using Vert.x

BEST PRACTICESLogger Verticle

●Disadvantages:

●log entries are not in order

●loss of log levels

●Solutions:

●use IDs to follow log message flow

●use one LoggerVerticle per log level

Page 17: Real World Enterprise Reactive Programming using Vert.x

BEST PRACTICES - On the fly deployment

Page 18: Real World Enterprise Reactive Programming using Vert.x

BEST PRACTICES - On the fly deployment

Page 19: Real World Enterprise Reactive Programming using Vert.x

●Do not block the loop

●put blocking code or extensive computation into

worker verticles

●Keep the application responsive

●stress test as often as possible

●Encapsulate common code in modules (more

on this later)

BEST PRACTICESIn General

Page 20: Real World Enterprise Reactive Programming using Vert.x

fat-jar: one package to rule the deployment

BEST PRACTICESDeployment

Page 21: Real World Enterprise Reactive Programming using Vert.x

BEST PRACTICESDeployment

zip-File:

●have a separate folder for scripts

●bind packaging to verify phase to have it all

with one command “mvn verify”

●complete example is on GitHub

Page 22: Real World Enterprise Reactive Programming using Vert.x

Internet

Auto Scaling group

Auto Scaling group

Availability Zone

Availability Zone

Page 23: Real World Enterprise Reactive Programming using Vert.x

Architecture

Page 24: Real World Enterprise Reactive Programming using Vert.x

Architecture

●Main framework Vert.x

●mod-kinesis (Kinesis-Adapter for Vert.x)

●AWS Java SDK

●IAM roles for Amazon EC2 instances

●Coda Hale metrics and CloudWatch reporter

●Jedis (Redis client for Java)

●…

Page 25: Real World Enterprise Reactive Programming using Vert.x

Deployment

WorkstationGitHub Jenkins

Python/Fabric

Nexus

Datacenter

Artefakt

Page 26: Real World Enterprise Reactive Programming using Vert.x

Deployment

Page 27: Real World Enterprise Reactive Programming using Vert.x

Deployment

EC2 instance with Dockerregistry (port 5000)

S3 bucket to store Docker images

Page 28: Real World Enterprise Reactive Programming using Vert.x

Deployment

Amazon Cloud

WorkstationGitHub Jenkins

Python/Boto

Docker Image

Docker RegistryS3 bucket withDocker Images

Page 29: Real World Enterprise Reactive Programming using Vert.x

Deployment

Page 30: Real World Enterprise Reactive Programming using Vert.x

Deployment

Page 31: Real World Enterprise Reactive Programming using Vert.x

Deployment

Page 32: Real World Enterprise Reactive Programming using Vert.x

Deployment

python start_docker_instance.py \

-r <myregistry>:5000 \

-i kinesis-producer \

-t 95 \

-q 2 \

-s quality \

-d '-d -p 8080:8080'

https://github.com/SaschaMoellering/aws-docker-scripts

Page 33: Real World Enterprise Reactive Programming using Vert.x

Deployment

python start_elb.py \

-r <myregistry>:5000 \

-i kinesis-producer \

-t 95 \

-s quality \

-d '-d -p 8080:8080'

https://github.com/SaschaMoellering/aws-docker-scripts

Page 34: Real World Enterprise Reactive Programming using Vert.x

Deployment

Page 35: Real World Enterprise Reactive Programming using Vert.x

Deployment

Page 36: Real World Enterprise Reactive Programming using Vert.x

Vert.x Module System

Page 37: Real World Enterprise Reactive Programming using Vert.x

Vert.x Module System

Benefits:

● Re-usable components as a zip file

● Maven and Bintray integration

● Vert.x module registry

● Vert.x downloads and installs modules for you

Page 38: Real World Enterprise Reactive Programming using Vert.x

Vert.x Module Registry

Page 39: Real World Enterprise Reactive Programming using Vert.x

Vert.x Event Bus

● Address is a simple string

● Types - Pub/Sub & P2P

Pub/Sub

P2P

Page 40: Real World Enterprise Reactive Programming using Vert.x

Sender

Receiver

Page 41: Real World Enterprise Reactive Programming using Vert.x

Integration with Messaging System

KAFKA MESSAGING SYSTEM

●Apache Kafka is a distributed publish-subscribe messaging system

●Fast

●Scalable

●Durable

●Distributed

Page 42: Real World Enterprise Reactive Programming using Vert.x

Integration with Messaging System

Main Terminology:

●Topic

●Producer

●Consumer

●Broker

Page 43: Real World Enterprise Reactive Programming using Vert.x

Kafka Module in Module Registry

Open source Kafka module in Vert.x’ module registry● http://modulereg.vertx.io/

Page 44: Real World Enterprise Reactive Programming using Vert.x

Using Vert.x Module

// programmatically

// command line

Page 45: Real World Enterprise Reactive Programming using Vert.x

Using Kafka Module

Configuration is a JSON object:

Page 46: Real World Enterprise Reactive Programming using Vert.x

StatsD Support

Config

Page 47: Real World Enterprise Reactive Programming using Vert.x

Metrics of Vert.x Project

On 4 Cores virtual machine we had the following

results:

●~28 K requests per second without Kafka,

with lookup from Redis

●~18 K requests per second with Kafka and

lookup from Redis

Page 48: Real World Enterprise Reactive Programming using Vert.x

Metrics of Vert.x Project

Test Traffic ~1000-3000 requests per minute:

●mean response time: 1-2ms

●90% of responses 0.86 ms

●fully cached: 0.65 ms

●CPU Load: 1-3%

●Memory: 90MB (300MB reserved)

Page 49: Real World Enterprise Reactive Programming using Vert.x

GET INVOLVED

Kafka Module - https://github.com/zanox/mod-kafka

Kinesis Module - https://github.com/zanox/mod-kinesis

Page 50: Real World Enterprise Reactive Programming using Vert.x

https://github.com/Mr-Steel/vertx_fatjar