An Introduction to Vert.x

28
JJUG CCC 2013 Fall R5-6 [BOF] An Introduction to Vert.x 2013/11/09 Acroquest Technology 株式会社 村田賢一郎 Over the Node.js

description

JJUG CCC 2013 Fall のスライド #jjug_ccc

Transcript of An Introduction to Vert.x

Page 1: An Introduction to Vert.x

JJUG CCC 2013 Fall R5-6 [BOF]

An Introduction to Vert.x

2013/11/09 Acroquest Technology 株式会社

村田賢一郎

Over the Node.js

Page 2: An Introduction to Vert.x

目次

1.  自己紹介 2.  Vert.x の概要 3.  Vert.x による開発 4.  Vert.x の最新情報 5.  まとめ

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 2

© http://www.flickr.com/photos/delta_139/4878497911/

〜Java界の新たなる希望〜

Page 3: An Introduction to Vert.x

1. 自己紹介

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 3

自己紹介 = 氏名: ‘村田 賢一郎’ twitter: ‘@muraken720’ 所属: ‘Acroquest Technology Co.,Ltd.’ 仕事:

‘ライフライン系ネットワーク集中監視システム開発’ ‘フレームワーク開発’

言語: ‘Java & JavaScript & CSS3 & HTML5’ 興味:

‘Vert.x’ ‘Backbone.js’

‘Jeet4’

Page 4: An Introduction to Vert.x

1. 自己紹介

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 4

n  最近は会社ブログで以下を書いています!

l  Vert.x がいいね!(第1回〜第3回) l  試して学ぶ Backbone.js 入門のまとめ l  RealtimeConf 2013に参加してきました!

http://acro-engineer.hatenablog.com/

Page 5: An Introduction to Vert.x

2. Vert.x の概要

Vert.x とは何なのか? その特長について

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 5

Page 6: An Introduction to Vert.x

【2. Vert.x の概要】

1. Vert.x とは?

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 6

〜Java界の新たなる希望〜

Page 7: An Introduction to Vert.x

1.  Project Site Ø  http://vertx.io/

2.  Github Ø  https://github.com/eclipse/vert.x Ø  https://github.com/vert-x

3.  100% open source(ASL 2.0) 4.  Eclipse Foundation Project 5.  主な開発者

Ø  @timfox (Project Leader) Ø  @normanmaurer

【2. Vert.x の概要】

2. Vert.x Project

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 7

Page 8: An Introduction to Vert.x

1.  High Performance(Asynchronous/ Non-Blocking)

2.  Distributed Event Bus

3.  Polyglot 4.  Module System

【2. Vert.x の概要】

3. Vert.x の特長

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 8

Page 9: An Introduction to Vert.x

1.  背景:C10K問題 ①  一般的に1つのスレッド辺り、256kb〜1mb必要になる

2.  対策:1スレッド(EventLoop)で処理する ①  Vert.xはコア数に応じて、EventLoopを生成する ②  non-blocking ③  asynchronous

【2. Vert.x の概要】

3-1. High Performance

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 9

© http://www.flickr.com/photos/stickkim/7491816206/

Page 10: An Introduction to Vert.x

n  EventLoopを止めるな! ①  ブロックするライブラリの呼び出し(例えばJDBC)

②  CPUヘビーな処理 ③  Thread.sleep() ④  Object.wait()

【2. Vert.x の概要】

3-1. High Performance

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 10

© http://www.flickr.com/photos/mac_filko/5085785977/

Page 11: An Introduction to Vert.x

n  Asynchronous API ①  TCP/SSL client & server ②  HTTP/HTTPS client & server ③  WebSocket ④  SockJS ⑤  File System ⑥  Event Bus ⑦  Timer ⑧  etc.

【2. Vert.x の概要】

3-1. High Performance

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 11

Page 12: An Introduction to Vert.x

1.  Event BusはVert.x のアプリケーション基盤 2.  Pub/Sub、Point to Point(Request / Response) 3.  メッセージはJSONが推奨 4.  複数のVert.x Instanceをクラスタリングしている場合も

Event Busで接続可能

【2. Vert.x の概要】

3-2. Distributed Event Bus

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 12

© http://www.flickr.com/photos/michellecarl/6960299327/

Page 13: An Introduction to Vert.x

n  JVM上で扱える多くの言語サポート

【2. Vert.x の概要】

3-3. Polyglot

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 13

© http://www.flickr.com/photos/johnnywashngo/6599602215/

Page 14: An Introduction to Vert.x

n  Java

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 14

public class HelloWorldVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { req.response().headers().set("Content-Type", "text/plain"); req.response().end("Hello World!!!"); } }).listen(8080); } }

【2. Vert.x の概要】

3-3. Polyglot

Page 15: An Introduction to Vert.x

n  Java8 ラムダ

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 15

public class HelloWorldVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler((HttpServerRequest req) -> { req.response().headers().set("Content-Type", "text/plain"); req.response().end("Hello World!!!"); }).listen(8080); } }

【2. Vert.x の概要】

3-3. Polyglot

Page 16: An Introduction to Vert.x

1.  機能を再利用可能な形にモジュール化することが可能 2.  モジュールはMavenやBintrayに公開し、共有すること

ができる 3.  モジュール間はEventBus介してゆるやかに結合する

【2. Vert.x の概要】

3-4. Module System

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 16

© http://www.flickr.com/photos/michellecarl/6960299327/

Page 17: An Introduction to Vert.x

1.  Moduleは1つ以上のVerticleを含むもの 2.  mod.jsonを定義する

【2. Vert.x の概要】

3-4. Module System

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 17

{ "main":”HelloVerticle", "auto-redeploy": true, "description":"Put description of your module here", "licenses": ["The Apache Software License Version 2.0"], "author": "Kenichiro Murata", "developers": [], "keywords": ["vert.x", "module", "java", "gradle"], "homepage": "https://github.com/muraken720/vert.x-module-template-for-java" }

Page 18: An Introduction to Vert.x

1.  Vert.x Module Registry Ø  http://modulereg.vertx.io/

2.  主なモジュール ①  WebServer ②  Mailer ③  MongoDB ④  Redis ⑤  JDBC ⑥  mysql-postgresql(async) ⑦  Yoke(inspired by Connect) ⑧  Vertigo(similar to Storm) ⑨  CRaSH shell

【2. Vert.x の概要】

3-4. Module System

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 18

Page 19: An Introduction to Vert.x

3. Vert.x による開発

Vert.x の開発環境からアプリケーションアーキテクチャについて

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 19

Page 20: An Introduction to Vert.x

1.  Java7 2.  Project Template

①  Gradle ②  Maven

3.  IDE Support ①  Eclipse ②  InteliJ

4.  Module Auto redeploy(デモ) 5.  Remote debug(デモ)

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 20

【3. Vert.x による開発】

1. 開発環境

参照: Vert.x がいいね!(第2回:開発環境を構築する)

http://acro-engineer.hatenablog.com/entry/2013/08/15/073502

Page 21: An Introduction to Vert.x

1.  Node.js and the new web front-end Ø  http://www.nczonline.net/blog/2013/10/07/node-js-and-

the-new-web-front-end/

2.  Node.jsでフロント側を開発して、バックエンド側をVert.xで開発する。

3.  EventBusを使ってNode.jsとVert.xをつなぐ Ø  vertx-eventbus-client Ø  https://npmjs.org/package/vertx-eventbus-client

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 21

【3. Vert.x による開発】

2. Vert.x を使ったアーキテクチャ

Page 22: An Introduction to Vert.x

4. Vert.x の最新情報

日本で最も早い?Vert.x の最新情報とVert.xの今後

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 22

Page 23: An Introduction to Vert.x

n  注目の新機能 ①  Fat Jar(executable jar)

– Vert.x Coreを含んだexecutable jarを作れる – 事前にVert.xをインストールしておく必要なし

②  HA(High Availability) ③  DNS / UDP Core API

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 23

【4. Vert.x の最新情報】

1. Vert.x 2.1 M1 Release

© http://www.flickr.com/photos/stickkim/6962834384/

Page 24: An Introduction to Vert.x

n  モジュールの自動フェールオーバー

【4. Vert.x の最新情報】

2. HA(High Availability)

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 24

In console 1:

vertx runmod com.mycompany~my-mod1~1.0 -ha

In console 2:

vertx runmod com.mycompany~my-mod2~1.0 -ha

© http://www.flickr.com/photos/stickkim/7108906575/

Page 25: An Introduction to Vert.x

n  HA Group

【4. Vert.x の最新情報】

2. HA(High Availability)

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 25

In console 1:

vertx runmod com.mycompany~my-mod1~1.0 -ha -hagroup g1

In console 2:

vertx runmod com.mycompany~my-mod2~1.0 -ha -hagroup g1

In console 3:

vertx runmod com.mycompany~my-mod3~1.0 -ha -hagroup g2

Page 26: An Introduction to Vert.x

5. まとめ

最後にVert.xのポイントをもう一度おさらい

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 26

Page 27: An Introduction to Vert.x

n  Vert.xは・・・ ①  次世代のApplication Platform ②  High Performance ③  Polyglot ④  Module System ⑤  EventBus

n  各JVM言語によるModuleを上手く組み合わせて、効率よく、ハイパフォーマンスでスケーラブルなアプリケーションを開発できる!

n  Java界の新たなる希望 Copyright © Acroquest Technology Co., Ltd. All rights reserved.

27

【5. まとめ】

まとめ

Page 28: An Introduction to Vert.x

Copyright © Acroquest Technology Co., Ltd. All rights reserved. 28

Java界の新たなる希望 『 Vert.x 』 で盛り上がりましょう!

ありがとうございました。

Infrastructures  Evolution