0
Copyright © 2015 TIS Inc. All rights reserved.
Scala関西Summit2015
Typesafe  Reactive  Platformで作る
Reactive  System
2015.8.1...
Copyright © 2015 TIS Inc. All rights reserved. 2
自己紹介
■ @yugolf  
■ 甲賀  ▶ 京都   ▶ 東京  
!
■ TIS株式会社  
■ 生産革新本部 生産革新部 生産技術R&D...
Copyright © 2015 TIS Inc. All rights reserved. 3
TIS、リアクティブコンサルはじめました
http://www.tis.jp/service_solution/goreactive/
Copyright © 2015 TIS Inc. All rights reserved. 4
Agenda
1. 	
  Reactive	
  Systemとは	
  
2. 	
  Reactive	
  Systemのための技術	
 ...
Copyright © 2015 TIS Inc. All rights reserved. 5
1.    Reactive	
  Systemとは
Copyright © 2015 TIS Inc. All rights reserved. 6
本日の話
http://www.reactivemanifesto.org/
Reactive	
  Programming:	
  
データの流...
Copyright © 2015 TIS Inc. All rights reserved. 7
Reactive  manifesto
絵	
  
!
即応性	
  
弾力性	
  
耐障害性	
  
メッセージ駆動
http://www.r...
Copyright © 2015 TIS Inc. All rights reserved. 8
アプリケーションへの高まる要求
50台のサーバで動かしていたけど、クラウド上で
1000コアの環境を作りたいんだ。
レスポンスを得るのに3秒かかる...
Copyright © 2015 TIS Inc. All rights reserved. 9
Reactive  Systemとは
即応性と、耐障害性と、弾力性と、メッセージ駆動とを備えたシステム
http://www.reactivema...
Copyright © 2015 TIS Inc. All rights reserved. 10
Reactive  Systemの価値
届けたい価値
手段
支える原理
高レスポンス  
Responsive
伸縮性  
Elastic
耐障...
Copyright © 2015 TIS Inc. All rights reserved. 11
Responsive
ユーザーの要求に迅速にレスポンスするシステム
高レスポンス  
Responsive
伸縮性  
Elastic
耐障害性...
Copyright © 2015 TIS Inc. All rights reserved. 12
Elastic
通常の負荷時だけでなく、一時的な高負荷状況でも、変動するワークロードに応
じて割り当てるリソースを増加・減少させることで応答時間...
Copyright © 2015 TIS Inc. All rights reserved. 13
Resilient
部分的な障害が発生した時にもシステム全体を危険にさらすことなく回復さ
せる高レスポンスを維持する
高レスポンス  
Resp...
Copyright © 2015 TIS Inc. All rights reserved. 14
Message  Driven
メッセージパッシングにより、コンポーネント間を疎結合にする
高レスポンス  
Responsive
伸縮性  
...
Copyright © 2015 TIS Inc. All rights reserved. 15
2.  Reactive	
  Systemのための技術
Copyright © 2015 TIS Inc. All rights reserved. 16
Typesafe  Reactive  Platform
JavaVM
アプリケーション
	
  AkkaPlay	
  Framework
S...
Copyright © 2015 TIS Inc. All rights reserved. 17
Play  Framework
• 非同期/ノンブロッキング	
  
• WebSocketサポート	
  
• Railsのような使いやすさ
Copyright © 2015 TIS Inc. All rights reserved. 18
これまで
def index = Action { implicit request =>

Ok(views.html.index())

}...
Copyright © 2015 TIS Inc. All rights reserved. 19
Blocking
コーヒーください。
コーヒー1つ∼
は∼い
できた∼
・・・
コーヒーどうぞ∼	
  
100円です。
コーヒーください。
コ...
Copyright © 2015 TIS Inc. All rights reserved. 20
Non-blocking
コーヒーください。
コーヒー1つ∼
は∼い
コーヒーどうぞ∼	
  
コーヒーください。
コーヒー1つ∼
100円です...
Copyright © 2015 TIS Inc. All rights reserved. 21
Reactive:  迅速なレスポンス
def index = Action.async {

val customer: Future[Cus...
Copyright © 2015 TIS Inc. All rights reserved. 22
Reactive++  :サーバからのプッシュ
クライアント サーバ
def socket = WebSocket.using[String] ...
Copyright © 2015 TIS Inc. All rights reserved. 23
Akka
• 並行処理と分散処理をサポートするActor	
  System	
  
• Supervision	
  Model	
  
• ...
Copyright © 2015 TIS Inc. All rights reserved. 24
Actor  System
sender
Actor
メッセージ駆動  
Message-driven
Mailbox
Mailbox
Copyright © 2015 TIS Inc. All rights reserved. 25
Reactive+++:  Actor  Model
def socket = WebSocket.acceptWithActor[String...
Copyright © 2015 TIS Inc. All rights reserved. 26
Supervision  Modelで障害に強いシステムに
override val supervisorStrategy: Superviso...
Copyright © 2015 TIS Inc. All rights reserved. 27
let	
  it	
  crash
Copyright © 2015 TIS Inc. All rights reserved. 28
Distribute
https://conductr.typesafe.com/docs/1.0.x/DeployingApplication
Copyright © 2015 TIS Inc. All rights reserved. 29
Reactive++++:  Actorを増減させ容易にスケール
クライアント
コントローラ
Actor
Actor
Actor
ルーティングは...
Copyright © 2015 TIS Inc. All rights reserved. 30
Reactive  Slick
Slick3
• FRM(Functional	
  Relational	
  Mapping)ライブラリ	
...
Copyright © 2015 TIS Inc. All rights reserved. 31
Supported  Databases
• MySQL	
  
• PostgreSQL	
  
• H2	
  
• HSQLDB/Hype...
Copyright © 2015 TIS Inc. All rights reserved. 32
Reactive+++++:  端から端までReactive
def search = Action.async { implicit requ...
Copyright © 2015 TIS Inc. All rights reserved. 33
端から端までReactive
基本Asynchronous、	
  
どこでWaitするかをデザインする
Copyright © 2015 TIS Inc. All rights reserved. 34
Reactive++++++:  Reactive  Streams
def search = Action.async { implicit ...
Copyright © 2015 TIS Inc. All rights reserved. 35
3.  プチReactive体験
Copyright © 2015 TIS Inc. All rights reserved. 36
プチReactive体験
発電してますか?
Copyright © 2015 TIS Inc. All rights reserved. 37
Reactive Solar Farm Monitor Solar Farm
① 何らかの原因で!
発電力が下がる
③ 故障が検知された!
ソー...
Copyright © 2015 TIS Inc. All rights reserved. 38
Architecture
Monitor Analyzer
Simulator
http!
&!
WebSocket
Subscriber
Pu...
Copyright © 2015 TIS Inc. All rights reserved. 39
Message  Passing
Sum	
  
Calculator
Sum	
  
Calculator InspectorInspecto...
Copyright © 2015 TIS Inc. All rights reserved. 40
Supervision  Model
AllForOne

Strategy
OneForOne

Strategy
Analysis	
  
...
Copyright © 2015 TIS Inc. All rights reserved. 41
プチReactive体験  -  Responsive
ユーザーの要求に可能な限り迅速にレスポンスするシステム
高レスポンス  
Respons...
Copyright © 2015 TIS Inc. All rights reserved. 42
プチReactive体験
支えているのはメッセージ駆動のアーキテクチャ
Copyright © 2015 TIS Inc. All rights reserved. 43
4.  Go  Reactive  ×  3
Copyright © 2015 TIS Inc. All rights reserved. 44
Go  Reactive  1/3
• アーキクチャの詳細	
  
• 時間の都合で出来なかったデモ
http://reactive-­‐shi...
Copyright © 2015 TIS Inc. All rights reserved. 45
Go  Reactive  2/3
http://www.tis.jp/service_solution/goreactive/
go-­‐re...
Copyright © 2015 TIS Inc. All rights reserved. 46
Go  Reactive  3/3
ソースコードはGitHubで公開しています。
太陽光発電に興味のある方はご連絡下さい。
https://gi...
THANK YOU
Upcoming SlideShare
Loading in...5
×

Typesafe Reactive Platformで作るReactive System

421

Published on

Scala関西Summit2015での発表資料です。

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
421
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Typesafe Reactive Platformで作るReactive System"

  1. 1. Copyright © 2015 TIS Inc. All rights reserved. Scala関西Summit2015 Typesafe  Reactive  Platformで作る Reactive  System 2015.8.1 前出 祐吾
  2. 2. Copyright © 2015 TIS Inc. All rights reserved. 2 自己紹介 ■ @yugolf   ■ 甲賀  ▶ 京都   ▶ 東京   ! ■ TIS株式会社   ■ 生産革新本部 生産革新部 生産技術R&D室   ■ 社内向けエンジニアリング基盤の整備 ▶▶
  3. 3. Copyright © 2015 TIS Inc. All rights reserved. 3 TIS、リアクティブコンサルはじめました http://www.tis.jp/service_solution/goreactive/
  4. 4. Copyright © 2015 TIS Inc. All rights reserved. 4 Agenda 1.  Reactive  Systemとは   2.  Reactive  Systemのための技術   3.  プチReactive体験
  5. 5. Copyright © 2015 TIS Inc. All rights reserved. 5 1.    Reactive  Systemとは
  6. 6. Copyright © 2015 TIS Inc. All rights reserved. 6 本日の話 http://www.reactivemanifesto.org/ Reactive  Programming:   データの流れ(ストリーム)とデータの値の変化の伝播にフォーカス したプログラムの設計モデル。   ・・・ の話ではない。 Reactive  System:
  7. 7. Copyright © 2015 TIS Inc. All rights reserved. 7 Reactive  manifesto 絵   ! 即応性   弾力性   耐障害性   メッセージ駆動 http://www.reactivemanifesto.org/ja
  8. 8. Copyright © 2015 TIS Inc. All rights reserved. 8 アプリケーションへの高まる要求 50台のサーバで動かしていたけど、クラウド上で 1000コアの環境を作りたいんだ。 レスポンスを得るのに3秒かかるけど、 500ミリ秒くらいにしたいのよ。   それと、年1回の2時間のメンテナンス なんとかならないかしら。 最初は100ギガくらいだったけど、そ ろそろペタ行くんじゃないかな。
  9. 9. Copyright © 2015 TIS Inc. All rights reserved. 9 Reactive  Systemとは 即応性と、耐障害性と、弾力性と、メッセージ駆動とを備えたシステム http://www.reactivemanifesto.org/ja
  10. 10. Copyright © 2015 TIS Inc. All rights reserved. 10 Reactive  Systemの価値 届けたい価値 手段 支える原理 高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven
  11. 11. Copyright © 2015 TIS Inc. All rights reserved. 11 Responsive ユーザーの要求に迅速にレスポンスするシステム 高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven 届けたい価値 手段 支える原理
  12. 12. Copyright © 2015 TIS Inc. All rights reserved. 12 Elastic 通常の負荷時だけでなく、一時的な高負荷状況でも、変動するワークロードに応 じて割り当てるリソースを増加・減少させることで応答時間を一定水準に保つ   高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven 届けたい価値 手段 支える原理
  13. 13. Copyright © 2015 TIS Inc. All rights reserved. 13 Resilient 部分的な障害が発生した時にもシステム全体を危険にさらすことなく回復さ せる高レスポンスを維持する 高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven 届けたい価値 手段 支える原理
  14. 14. Copyright © 2015 TIS Inc. All rights reserved. 14 Message  Driven メッセージパッシングにより、コンポーネント間を疎結合にする 高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven 届けたい価値 手段 支える原理
  15. 15. Copyright © 2015 TIS Inc. All rights reserved. 15 2.  Reactive  Systemのための技術
  16. 16. Copyright © 2015 TIS Inc. All rights reserved. 16 Typesafe  Reactive  Platform JavaVM アプリケーション  AkkaPlay  Framework Scala Java Slick 高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven
  17. 17. Copyright © 2015 TIS Inc. All rights reserved. 17 Play  Framework • 非同期/ノンブロッキング   • WebSocketサポート   • Railsのような使いやすさ
  18. 18. Copyright © 2015 TIS Inc. All rights reserved. 18 これまで def index = Action { implicit request =>
 Ok(views.html.index())
 } クライアント サーバ 高レスポンス   Responsive ブロッキ ング
  19. 19. Copyright © 2015 TIS Inc. All rights reserved. 19 Blocking コーヒーください。 コーヒー1つ∼ は∼い できた∼ ・・・ コーヒーどうぞ∼   100円です。 コーヒーください。 コーヒー1つ∼ Block
  20. 20. Copyright © 2015 TIS Inc. All rights reserved. 20 Non-blocking コーヒーください。 コーヒー1つ∼ は∼い コーヒーどうぞ∼   コーヒーください。 コーヒー1つ∼ 100円です。 100円です。 は∼い できた∼ コーヒーください。
  21. 21. Copyright © 2015 TIS Inc. All rights reserved. 21 Reactive:  迅速なレスポンス def index = Action.async {
 val customer: Future[Customer] = getCustomer()
 customer.map(c => Ok("Customer: " + c))
 } クライアント サーバ サービス 高レスポンス   Responsive ノンブロッ キング ノンブロッ キング
  22. 22. Copyright © 2015 TIS Inc. All rights reserved. 22 Reactive++  :サーバからのプッシュ クライアント サーバ def socket = WebSocket.using[String] { request =>
 
 // Log events to the console
 val in = Iteratee.foreach[String](println).map { _ =>
 println("Disconnected")
 }
 
 // Send a single 'Hello!' message
 val out = Enumerator("Hello!")
 
 (in, out)
 } 高レスポンス   Responsive ノンブロッ キング WebSocket https://www.playframework.com/documentation/2.4.x/ScalaWebSockets
  23. 23. Copyright © 2015 TIS Inc. All rights reserved. 23 Akka • 並行処理と分散処理をサポートするActor  System   • Supervision  Model   • 位置透過性
  24. 24. Copyright © 2015 TIS Inc. All rights reserved. 24 Actor  System sender Actor メッセージ駆動   Message-driven Mailbox Mailbox
  25. 25. Copyright © 2015 TIS Inc. All rights reserved. 25 Reactive+++:  Actor  Model def socket = WebSocket.acceptWithActor[String, String] { request => out =>
 MyWebSocketActor.props(out)
 } object MyWebSocketActor {
 def props(out: ActorRef) = Props(new MyWebSocketActor(out))
 }
 
 class MyWebSocketActor(out: ActorRef) extends Actor {
 def receive = {
 case msg: String =>
 out ! ("I received your message: " + msg)
 }
 } クライアント コントローラ Actor 伸縮性   Elastic 耐障害性   Resilient ノンブロッ キング WebSocket Actor https://www.playframework.com/documentation/2.4.x/ScalaWebSockets
  26. 26. Copyright © 2015 TIS Inc. All rights reserved. 26 Supervision  Modelで障害に強いシステムに override val supervisorStrategy: SupervisorStrategy =
 AllForOneStrategy(maxNrOfRetries = 100, withinTimeRange = 1 minute) {
 case _ => Restart
 } スーパー   バイザー サブスーパー   バイザー Actor Actor Actor 運命共同体   -­‐OneForOne   -­‐AllForOne 障害を外へ波及させない 耐障害性   Resilient 子アクターの監視役
  27. 27. Copyright © 2015 TIS Inc. All rights reserved. 27 let  it  crash
  28. 28. Copyright © 2015 TIS Inc. All rights reserved. 28 Distribute https://conductr.typesafe.com/docs/1.0.x/DeployingApplication
  29. 29. Copyright © 2015 TIS Inc. All rights reserved. 29 Reactive++++:  Actorを増減させ容易にスケール クライアント コントローラ Actor Actor Actor ルーティングは様々   • ランダム   • ラウンドロビン   • ブロードキャスト   • 早いの採用 伸縮性   Elastic ノンブロッ キング WebSocket Actor
  30. 30. Copyright © 2015 TIS Inc. All rights reserved. 30 Reactive  Slick Slick3 • FRM(Functional  Relational  Mapping)ライブラリ   • Scalaのコレクションを扱うかのようにデータベースにアクセス出来る   • DB処理は非同期に実行される
  31. 31. Copyright © 2015 TIS Inc. All rights reserved. 31 Supported  Databases • MySQL   • PostgreSQL   • H2   • HSQLDB/HyperSQL   • SQLite   • Derby/JavaDB   • Microsoft  Access • DB2   • Microsoft  SQL  Server   • Oracle Slick  Extensions
  32. 32. Copyright © 2015 TIS Inc. All rights reserved. 32 Reactive+++++:  端から端までReactive def search = Action.async { implicit request => …
 val f:Future[Seq[EventRow]] = db.run(Events.filter(form)) f.map {
 case events if (events.length > 0) =>
 Ok(views.html.sample.search( form.bindFromRequest, events))
 case _ =>
 … 高レスポンス   Responsive クライアント コントローラ ノンブロッ キング WebSocket Actor ノンブロッ キング Actor データベース
  33. 33. Copyright © 2015 TIS Inc. All rights reserved. 33 端から端までReactive 基本Asynchronous、   どこでWaitするかをデザインする
  34. 34. Copyright © 2015 TIS Inc. All rights reserved. 34 Reactive++++++:  Reactive  Streams def search = Action.async { implicit request => …
 val q = for(e <- Event) yield e.eventNm val publisher:DatabasePublisher[String] = db.stream(q.result) publisher.foreach {e => println(e)} … 高レスポンス   Responsive クライアント コントローラ ノンブロッ キング WebSocket Actor ノンブロッ キング データベース Actor
  35. 35. Copyright © 2015 TIS Inc. All rights reserved. 35 3.  プチReactive体験
  36. 36. Copyright © 2015 TIS Inc. All rights reserved. 36 プチReactive体験 発電してますか?
  37. 37. Copyright © 2015 TIS Inc. All rights reserved. 37 Reactive Solar Farm Monitor Solar Farm ① 何らかの原因で! 発電力が下がる ③ 故障が検知された! ソーラパネルの! アラートを表示 ID:  45412 ② 全ソーラーパネルの! 電力(W)から故障! しているパネルを検知 ソーラーパネルがそれぞれ定期的に! 発電した電力(W)のデータを送信! ・毎秒送信! ・パネル数は1万∼10万枚を想定
 ID:  45412 Reactive  Solar  Farm  Monitor Icon  made  by  Freepik  from  www.flaticon.com  is  licensed  under  CC  BY  3.0
  38. 38. Copyright © 2015 TIS Inc. All rights reserved. 38 Architecture Monitor Analyzer Simulator http! &! WebSocket Subscriber Publisher Broker
  39. 39. Copyright © 2015 TIS Inc. All rights reserved. 39 Message  Passing Sum   Calculator Sum   Calculator InspectorInspector Packet Mean Alert Snapshot Packet Inspection   Channel Buffer   Channel Socket Buffer Broker Execute Take
 Snapshot Collect
 Ghosts Partial  Sum Inspection   Manager Sum   Calculator Execute Inspector Done Sample Sample AnalyzerProxy Mean   Calculator Execute Measurement Measurement SocketSocket
  40. 40. Copyright © 2015 TIS Inc. All rights reserved. 40 Supervision  Model AllForOne
 Strategy OneForOne
 Strategy Analysis   Supervisor Calculation   Supervisor Inspection   Manager Inspector Inspection   Channel BufferBuffer   Channel Sum   Calculator Mean   Calculator Inspection   Supervisor AllForOne
 Strategy User
  41. 41. Copyright © 2015 TIS Inc. All rights reserved. 41 プチReactive体験  -  Responsive ユーザーの要求に可能な限り迅速にレスポンスするシステム 高レスポンス   Responsive 伸縮性   Elastic 耐障害性   Resilient メッセージ駆動   Message-driven
  42. 42. Copyright © 2015 TIS Inc. All rights reserved. 42 プチReactive体験 支えているのはメッセージ駆動のアーキテクチャ
  43. 43. Copyright © 2015 TIS Inc. All rights reserved. 43 4.  Go  Reactive  ×  3
  44. 44. Copyright © 2015 TIS Inc. All rights reserved. 44 Go  Reactive  1/3 • アーキクチャの詳細   • 時間の都合で出来なかったデモ http://reactive-­‐shinjuku.connpass.com/event/17991/
  45. 45. Copyright © 2015 TIS Inc. All rights reserved. 45 Go  Reactive  2/3 http://www.tis.jp/service_solution/goreactive/ go-­‐reactive@tis.co.jpリアクティブに興味のある方はご連絡下さい。
  46. 46. Copyright © 2015 TIS Inc. All rights reserved. 46 Go  Reactive  3/3 ソースコードはGitHubで公開しています。 太陽光発電に興味のある方はご連絡下さい。 https://github.com/tech-­‐sketch/reactive-­‐solar-­‐farm-­‐monitor go-­‐reactive@tis.co.jp
  47. 47. THANK YOU
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×