annotate slides/20170123/slide.md @ 3:9175e77652b3

add 20170123 slides
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 23 Jan 2018 19:26:41 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 title: 分散フレームワークakkaの調査
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 author: Takahiro Shimizu
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 profile:
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 lang: Japanese
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 # 調査目的
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 * 先輩の修論の比較材料の為に行う
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 * 分散フレームワークの1つであるakkaがどのような書き方、及び処理なのかを調査する
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 # 今週の進捗
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 * scalaの入門書を斜め読みした
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 * akkaの公式チュートリアルを行った
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 * Graphでn入力1出力のアクターモデルが生成出来ることを調べた
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 * ドキュメントの例題を実行した
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 # 調査内容
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 * akkaのmac osx,ubuntu上の導入
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 * [公式チュートリアル](https://developer.lightbend.com/guides/akka-quickstart-java/)の例題を行う
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 * 前回はJavaで実行した
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 * scalaで今回再調査を行いました
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 # scala環境の構築
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 * brewやaptで導入した
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 * scalaという名前のパッケージもあるが、sbtで導入する
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 * `~/.sbt` 以下のディレクトリにバージョンごと入る為、適切に処理しないと競合する
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 # akkaでn入力の処理
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 * [GraphDSL](https://doc.akka.io/docs/akka/current/stream/stream-graphs.html?language=scala#constructing-graphs)系の命令を利用すると実行可能
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 * [Github上の別のサンプル](https://github.com/pkinsky/akka-streams-example)
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 # 出力系
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 * Broadcast[T]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 * (1input N output) 1入力に対して全てのoutputに渡す
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 * Balance[T]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 * (1input N outputs) outputを1つ指定して出力をする
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 * unzipWith[In,A,B..]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 * 関数を受取,20までの各要素に対して実行する
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 * unZip[A,B]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 * Tupleを分割して、2つのoutputに対して送る
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 # input系
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 * Merge[In]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 * MergePreferred[In]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 * MergePrioritized[In]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 * ZipWith[A,B,...,Out]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 * Zip[A,B]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 * Concat[A]
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 # チュートリアル
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 ```scala
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 package merger
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 import akka.NotUsed
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 import akka.actor.ActorSystem
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 import akka.routing.Broadcast
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 import akka.stream.{ClosedShape, OverflowStrategy}
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 import akka.stream.scaladsl.{Flow, GraphDSL, Merge, RunnableGraph, Sink, Source}
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 object merger extends App {
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 val system: ActorSystem = ActorSystem("mergeAkka")
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 val g = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder: GraphDSL.Builder[NotUsed] =>
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 import GraphDSL.Implicits._
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 val in = Source(1 to 10)
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 val out = Sink.ignore
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 val bcast = builder.add(Broadcast[Int](2))
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 val merge = builder.add(Merge[Int](2))
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 val f1, f2, f3, f4 = Flow[Int].map(_ + 10)
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 in ~> f1 ~> bcast ~> f2 ~> merge ~> f3 ~> out
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 bcast ~> f4 ~> merge
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 ClosedShape
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 })
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 }
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 ```
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 # 詰まっている所
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 * 公式のサンプルコードを動かそうとすると型エラーが発生する
9175e77652b3 add 20170123 slides
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 * コンパニオンオブジェクトの書き方があまり理解できていない