SlideShare a Scribd company logo
1 of 46
Download to read offline
Process Design and Polymorphism:
Lessons Learnt from Development of Kai
takemaru
08.11.20
1
Outline
  Reviewing Dynamo and Kai
  Kai: an Open Source Implementation of Amazon’s Dynamo
  Features and Mechanism
  Process Design for Better Performance
  Based on Calling Sequence and Process State
  Polymorphism in Actor Model
  Two approaches to implement polymorphism
08.11.20
2
Dynamo: Features
3
  Key, value store
  Distributed hash table
  High scalability
  No master, peer-to-peer
  Large scale cluster, maybe O(1K)
  Fault tolerant
  Even if an entire data center fails
  Meets latency requirements in the case
08.11.20
get(“cart/joe”)
joe
joe
joe
Dynamo: Partitioning
08.11.20
4
  Consistent Hashing
  Nodes and keys are
positioned at their hash
values
  MD5 (128bits)
  Keys are stored in the
following N nodes
joe
Hash ring (N=3)
2^128
0
 1
 2
hash(node3)
hash(node1)
hash(node2)
hash(node5)
hash(node4)
hash(cart/joe)
hash(node6)
Dynamo: Membership
08.11.20
5
  Gossip-based protocol
  Spreads membership like a
rumor
  Membership contains node list
and change history
  Exchanges membership with a
node at random every second
  Updates membership if more
recent one received
  Advantages
  Robust; no one can prevent a
rumor from spreading
  Exponentially rapid spread
Membership change is spread
by the form of gossip
Detecting node failure
hash(node2)
node2 is down
node2 is down
node2 is down
node2 is down
Dynamo:
get/put Operations
08.11.20
6
  Client
1.  Sends a request any of
Dynamo node
  The request is forwarded to
coordinator
  Coordinator: one of nodes
associated with the key
  Coordinator
1.  Chooses N nodes by using
consistent hashing
2.  Forwards a request to N
nodes
3.  Waits responses from R or
W nodes, or timeouts
4.  Checks replica versions if get
5.  Sends a response to client
get/put operations for N,R,W = 3,2,2
Request
Response
Client
Coordinator
joe
joe
joe
Kai: Overview
08.11.20
7
  Kai
  Open source implementation of Amazon’s Dynamo
  Named after my origin
  OpenDynamo had been taken by a project not related to Amazon’s
Dynamo 
  Written in Erlang
  memcache API
  Found at http://sourceforge.net/projects/kai/
Process Design for Better
Performance
08.11.20
8
Two approaches to improve software
performance
08.11.20
9
  To process it with less CPU resource
  Solved by introducing better algorithms
  e.g. Binary search is used instead of linear search
  To use all CPU resources
  Issues identified in multi-core environment
  Solved by rearranging process-core mapping
  e.g. Heavy process and light process run on multi-core
1st core
2nd core
boring…
heavy process
light process
Two approaches to improve software
performance
08.11.20
10
  To process it with less CPU resource
  Solved by introducing better algorithms
  e.g. Binary search is used instead of linear search
  To use all CPU resources
  Issues identified in multi-core environment
  Solved by rearranging process-core mapping
  e.g. Heavy process and light process run on multi-core
1st core
2nd core
work! work!
heavy process
light process
Latter case will be discussed
Diagram Convention
08.11.20
11
  Procedural programming
  Procedures are called by a process
foo
 bar
process foo
-module(foo).
-behaviour(gen_server).
ok(State) ->
{reply, bar:ok(), State}.
-module(bar).
ok() ->
ok.
process
ellipse
rectangle
 not process
Diagram Convention, cont’d
08.11.20
12
  Actor model
  2 processes interact with each other
foo
 bar
-module(bar).
-behaviour(gen_server).
ok(State) ->
{reply, ok, State}.
ok() ->
gen_server:call(?MODULE, ok).
process bar
process foo
process
ellipse
rectangle
 not process
-module(foo).
-behaviour(gen_server).
ok(State) ->
{reply, bar:ok(), State}.
Design Rules in Erlang
08.11.20
13
  Some of rules on process design:
  “Assign exactly one parallel process to each true concurrent activity
in the system”
  “Each process should only have one role”
  from Program Development Using Erlang - Programming Rules and
Conventions
Processes in getting/putting data
08.11.20
14
Node 1
coordinator
Node 2
Client
 memcache
 rpc
 rpc
For clarity, details of architecture are omitted.
store
data
coordinator
rpc
Choosing a node having
responsibility for requested key
Node 2
Node 1
Sequence in getting/putting data
08.11.20
15
memcache
 coordinator
 rpc
 coordinator
 store
Client
Blocked…
Node 2
Node 1
Sequence in getting/putting data, cont’d
08.11.20
16
memcache
 coordinator
 rpc
 coordinator
 store
Client
Another client
Blocked…
Node 2
Node 1
Sequence in getting/putting data, cont’d
08.11.20
17
memcache
 coordinator
 rpc
 coordinator
 store
Client
Another client
Accepted and…
Blocked!
Design Rules in Erlang, again
08.11.20
18
  Another rule on process design:
  “Use many processes”
  Many processes are almost uniformly assigned to each processor by
statistical effect
  from Chap.20 Programming Erlang
Processes in getting/putting data, again
08.11.20
19
Node 1
coordinator
Node 2
Client
 rpc
store
data
coordinator
rpc
memcache
memcache
 rpc
rpc
coordinator
 coordinator
For clarity, details of architecture are omitted.
Spawning multiple coordinator processes
Node 2
Node 1
Sequence in getting/putting data, again
08.11.20
20
memcache
 coordinator
 rpc
 coordinator
 store
Client
Another client
Accepted and…
Node 2
Node 1
Sequence in getting/putting data, again
08.11.20
21
memcache
 coordinator
 rpc
 coordinator
 store
Client
Another client
Accepted and…
Spawned
It’s OK, but looks like overkill.
Concurrency is produced by memcache module.
Why it is reproduced by coordinator?
Design Rules in Erlang, in final
08.11.20
22
  Another rule on process design:
  “Don’t spawn stateless processes”
  Called as procedures from concurrent processes
  Introduced by me 
Processes in getting/putting data, in final
08.11.20
23
Node 1
 Node 2
Client
 rpc
store
data
rpc
memcache
memcache
 rpc
rpc
For clarity, details of architecture are omitted.
Not spawned
coordinator
 coordinator
Node 2
Node 1
Sequence in getting/putting data, in final
08.11.20
24
memcache/coordinator
 rpc
 coordinator
 store
Client
Another client
Accepted and processed
Lessons Learnt
08.11.20
25
  Process design based on calling sequence and process state
  Externally called module
  Must be spawned to produce concurrency
  Runs as multiple processes if needed
  e.g.TCP listening process, timer process
  Stateless module
  No need to be spawned
  e.g. coordinator of Kai
  Stateful module
  Should be spawned for state consistency
  Runs as multiple processes if possible
  If a single process, it must be a terminal one (never call other processes
synchrnously) to avoid blocking
  e.g. database process, socket pool
Process Relationship in Kai
08.11.20
26
memcache
store
data
memcache
 rpc
rpc
hash
members,
buckets
connection
version
coordinator
sockets
process
ellipse
rectangle
 not process
state
current
version
vclock
config
configs
Relationships between stateful processes
and other modules are omitted.
Process Relationship in Kai, cont’d
08.11.20
27
store
data
rpc
rpc
hash
members,
buckets
connection
version
sockets
process
ellipse
rectangle
 not process
membership
sync
with timer
vclock
current
version
config
configs
Relationships between stateful processes
and other modules are omitted.
Process Relationship in Kai, cont’d
08.11.20
28
  “Lessons learnt” are almost satisfied
  Externally called modules are spawned
  As multiple processes if needed
  e.g. kai_rpc, kai_memcache, kai_sync, kai_membership
  Stateless modules are not spawned
  e.g. kai_coordinator
  Stateful modules are spawned
  e.g. kai_config, kai_version, kai_store, kai_hash, kai_connection
  However, some of them are NOT terminal ones
  e.g. connection module calling config process, is potential bottle neck
  “Lessons learnt” can point out potential bottle necks
  Yes, connection module is just a thing!
Advanced Issues
08.11.20
29
  More concurrency may be introduced if needed
  Design rules from “Lessons Learnt” can be applied locally
  e.g. coordinator produces N concurrency for asynchronous
calls
  Referred to Web application servers in MVC model
Web application servers
 Process Design from
“Lessons Learnt”
Concurrency is
produced by
Web servers, e.g.Apache
 Externally called modules
Application is
controlled by
Controller of MVC
 Stateless modules
State is managed by
 Model of MVC
 Stateful modules
Advanced Issues, cont’d
08.11.20
30
  Is blocking never occurred in pure functional
programming?
  In Kai, a process receiving requests waits for data to be replied
  In pure functional programming, another process handles data
to be replied?
  Not straightforward for me…
Blocking
Req.
 Req. and socket
Res.
 Res. and socket
Kai
 Pure functional programming model?
Polymorphism in Actor Model
08.11.20
31
What’s Polymorphism?
08.11.20
32
  “a programming language feature that allows values of
different data types to be handled using a uniform
interface”
  from Wikipedia
Polymorphism in Java
08.11.20
33
  Interface
  Implementation class
interface Animal {
void bark();
}
class Dog implements Animal {
public void bark() {
System.out.println(“Bow wow”);
}
}
Including no implementation
Polymorphism in Java, cont’d
08.11.20
34
  Abstract class
  Concrete class
abstract class Animal {
public void bark() {
System.out.println(this.yap());
}
abstract String yap();
}
class Dog extends Animal {
String yap() {
return “Bow wow”;
}
}
Including some implementation
Polymorphism Inspired by Interface
08.11.20
35
  Interface module
  Initializes implementation module with a name
  Calls the process with the name
  Implementation module
  Spawns a process and registers it as the given name
  Implements actual logics, which are called from interface
Polymorphism Inspired by Interface, cont’d
08.11.20
36
-module(animal).
start_link(Mod) ->
Mod:start_link(?MODULE).
bark() ->
gen_server:call(?MODULE, bark).
-module(dog).
-behaviour(gen_server).
start_link(ServerName) ->
gen_server:start_link({local, ServerName}, ?MODULE, [], []).
handle_call(bark, _From, State) ->
bark(State).
bark(State) -> 
io:format(“Bow wow~n”),
{reply, ok, State}.
Some required callbacks are omitted.
Polymorphism Inspired by Interface, cont’d
08.11.20
37
  How to use
animal:start_link(dog),
animal:bark(). % Bow wow
Polymorphism Inspired by Interface, cont’d
08.11.20
38
  Example in Kai
  Provides two types of local storage with a single interface
  Interface module
  kai_store
  Implementation modules
  kai_store_ets, uses ets, memory storage
  kai_store_dets, uses dets, disk storage
  See actual codes in detail
Polymorphism Inspired by Abstract Class
08.11.20
39
  Abstract module
  Defines abstract functions by using behavior mechanism
  Spawns a process and stores a name of concrete module
  Implements base logics
  Calls the process
  Concrete module
  Implements callbacks, which are called from the abstract
module
Polymorphism Inspired by Abstract Class,
cont’d
08.11.20
40
-module(animal).
-behaviour(gen_sever).
behaviour_info(callbacks) -> [{yap, 0}]; % abstract void yap();
behaviour_info(_Other) -> undefined.
start_link(Mod) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [Mod], []).
init(_Args = [Mod]) ->
{ok, _State = {Mod}}.
bark(_State = {Mod}) ->
io:format("~s~n", [Mod:yap()]),
{reply, ok, Mod}.
handle_call(bark, _From, State) ->
bark(State).
bark() ->
gen_server:call(?MODULE, bark).
Some required callbacks are omitted.
Polymorphism Inspired by Abstract Class,
cont’d
08.11.20
41
  How to use
  Same as an example of interface
-module(dog).
-behaviour(animal).
yap() ->
"Bow wow”.
animal:start_link(dog),
animal:bark(). % Bow wow
Polymorphism Inspired by Abstract Class,
cont’d
08.11.20
42
  Example in Kai
  Provides two types of TCP listening processes with a single
interface
  Abstract module (behavior)
  kai_tcp_server
  Concrete modules
  kai_rpc, listens RPC calls from other Kai nodes
  kai_memcache, listens requests from memcache clients
  See actual codes in detail
Lessons Learnt
08.11.20
43
  Two approaches to implement polymorphism
  Inspired by interface
  Simple
  Not efficient
  Actual logics have to be implemented in each child
  Inspired by abstract class
  Erlang-way
  Efficient
  Abstract class can be shared by children
Summary
08.11.20
44
Outline
  Reviewing Dynamo and Kai
  Kai: an Open Source Implementation of Amazon’s Dynamo
  Features and Mechanism
  Process Design for Better Performance
  Process Design Based on Calling Sequence and Process State
  Polymorphism in Actor Model
  Two approaches to implement polymorphism
08.11.20
45
Kai: Roadmap
08.11.20
46
1.  Initial implementation (May, 2008)
  1,000 L
2.  Current status
  2,200 L
  Following tickets done
Module
 Task
kai_coordinator
 Requests from clients will be routed to coordinators
kai_version
 Vector clocks
kai_store
 Persistent storage
kai_rpc, kai_memcache
 Process pool
kai_connection
 Connection pool

More Related Content

What's hot

Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...
Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...
Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...Guozhang Wang
 
Flink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache Flink
Flink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache FlinkFlink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache Flink
Flink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache FlinkFlink Forward
 
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache FlinkTzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache FlinkVerverica
 
Synapse 2018 Guarding against failure in a hundred step pipeline
Synapse 2018 Guarding against failure in a hundred step pipelineSynapse 2018 Guarding against failure in a hundred step pipeline
Synapse 2018 Guarding against failure in a hundred step pipelineCalvin French-Owen
 
Task Parallel Library Data Flows
Task Parallel Library Data FlowsTask Parallel Library Data Flows
Task Parallel Library Data FlowsSANKARSAN BOSE
 
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkMaximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkFlink Forward
 
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy FarkasVirtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy FarkasFlink Forward
 
Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...
Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...
Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...Flink Forward
 
Aioug connection poolsizingconcepts
Aioug connection poolsizingconceptsAioug connection poolsizingconcepts
Aioug connection poolsizingconceptsToon Koppelaars
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"LogeekNightUkraine
 

What's hot (14)

Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...
Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...
Consistency and Completeness: Rethinking Distributed Stream Processing in Apa...
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
Flink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache Flink
Flink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache FlinkFlink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache Flink
Flink Forward Berlin 2017: Tzu-Li (Gordon) Tai - Managing State in Apache Flink
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Unified Stream and Batch Processing with Apache Flink
Unified Stream and Batch Processing with Apache FlinkUnified Stream and Batch Processing with Apache Flink
Unified Stream and Batch Processing with Apache Flink
 
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache FlinkTzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
 
Synapse 2018 Guarding against failure in a hundred step pipeline
Synapse 2018 Guarding against failure in a hundred step pipelineSynapse 2018 Guarding against failure in a hundred step pipeline
Synapse 2018 Guarding against failure in a hundred step pipeline
 
Task Parallel Library Data Flows
Task Parallel Library Data FlowsTask Parallel Library Data Flows
Task Parallel Library Data Flows
 
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkMaximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy FarkasVirtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
 
Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...
Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...
Flink Forward Berlin 2017: Andreas Kunft - Efficiently executing R Dataframes...
 
Aioug connection poolsizingconcepts
Aioug connection poolsizingconceptsAioug connection poolsizingconcepts
Aioug connection poolsizingconcepts
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"
 

Similar to Process Design and Polymorphism: Lessons Learnt from Development of Kai

20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPMcamunda services GmbH
 
The Next Generation of Data Processing and Open Source
The Next Generation of Data Processing and Open SourceThe Next Generation of Data Processing and Open Source
The Next Generation of Data Processing and Open SourceDataWorks Summit/Hadoop Summit
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding SchemeRajesh Piryani
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuningprathap kumar
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software PerformanceGibraltar Software
 
Membase Meetup 2010
Membase Meetup 2010Membase Meetup 2010
Membase Meetup 2010Membase
 
User-space Network Processing
User-space Network ProcessingUser-space Network Processing
User-space Network ProcessingRyousei Takano
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkbanq jdon
 
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Bhupesh Bansal
 
Hadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop User Group
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Databricks
 
Productionalizing ML : Real Experience
Productionalizing ML : Real ExperienceProductionalizing ML : Real Experience
Productionalizing ML : Real ExperienceIhor Bobak
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataDataWorks Summit/Hadoop Summit
 
Bottlenecks rel b works and rel c planning
Bottlenecks rel b works and rel c planningBottlenecks rel b works and rel c planning
Bottlenecks rel b works and rel c planningJun Li
 

Similar to Process Design and Polymorphism: Lessons Learnt from Development of Kai (20)

20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM
 
The Next Generation of Data Processing and Open Source
The Next Generation of Data Processing and Open SourceThe Next Generation of Data Processing and Open Source
The Next Generation of Data Processing and Open Source
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding Scheme
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
 
Nexmark with beam
Nexmark with beamNexmark with beam
Nexmark with beam
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software Performance
 
Membase Meetup 2010
Membase Meetup 2010Membase Meetup 2010
Membase Meetup 2010
 
User-space Network Processing
User-space Network ProcessingUser-space Network Processing
User-space Network Processing
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
GCF
GCFGCF
GCF
 
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
 
Hadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedIn
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...
 
Mumak
MumakMumak
Mumak
 
Productionalizing ML : Real Experience
Productionalizing ML : Real ExperienceProductionalizing ML : Real Experience
Productionalizing ML : Real Experience
 
How To Scale v2
How To Scale v2How To Scale v2
How To Scale v2
 
.net Framework
.net Framework.net Framework
.net Framework
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing data
 
Bottlenecks rel b works and rel c planning
Bottlenecks rel b works and rel c planningBottlenecks rel b works and rel c planning
Bottlenecks rel b works and rel c planning
 

More from Takeru INOUE

分散ストレージに使えるかもしれないアルゴリズム
分散ストレージに使えるかもしれないアルゴリズム分散ストレージに使えるかもしれないアルゴリズム
分散ストレージに使えるかもしれないアルゴリズムTakeru INOUE
 
Rewind the last half year for Erlang
Rewind the last half year for ErlangRewind the last half year for Erlang
Rewind the last half year for ErlangTakeru INOUE
 
Kai = (Dynamo + memcache API) / Erlang
Kai = (Dynamo + memcache API) / ErlangKai = (Dynamo + memcache API) / Erlang
Kai = (Dynamo + memcache API) / ErlangTakeru INOUE
 
Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)
Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)
Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)Takeru INOUE
 
Kai – An Open Source Implementation of Amazon’s Dynamo
Kai – An Open Source Implementation of Amazon’s DynamoKai – An Open Source Implementation of Amazon’s Dynamo
Kai – An Open Source Implementation of Amazon’s DynamoTakeru INOUE
 
Amazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LT
Amazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LTAmazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LT
Amazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LTTakeru INOUE
 
Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008Takeru INOUE
 

More from Takeru INOUE (7)

分散ストレージに使えるかもしれないアルゴリズム
分散ストレージに使えるかもしれないアルゴリズム分散ストレージに使えるかもしれないアルゴリズム
分散ストレージに使えるかもしれないアルゴリズム
 
Rewind the last half year for Erlang
Rewind the last half year for ErlangRewind the last half year for Erlang
Rewind the last half year for Erlang
 
Kai = (Dynamo + memcache API) / Erlang
Kai = (Dynamo + memcache API) / ErlangKai = (Dynamo + memcache API) / Erlang
Kai = (Dynamo + memcache API) / Erlang
 
Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)
Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)
Kai – An Open Source Implementation of Amazon’s Dynamo (in Japanese)
 
Kai – An Open Source Implementation of Amazon’s Dynamo
Kai – An Open Source Implementation of Amazon’s DynamoKai – An Open Source Implementation of Amazon’s Dynamo
Kai – An Open Source Implementation of Amazon’s Dynamo
 
Amazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LT
Amazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LTAmazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LT
Amazon's Dynamo in POE and Erlang @ YAPC::Asia 2008 LT
 
Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008
 

Recently uploaded

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Process Design and Polymorphism: Lessons Learnt from Development of Kai

  • 1. Process Design and Polymorphism: Lessons Learnt from Development of Kai takemaru 08.11.20 1
  • 2. Outline   Reviewing Dynamo and Kai   Kai: an Open Source Implementation of Amazon’s Dynamo   Features and Mechanism   Process Design for Better Performance   Based on Calling Sequence and Process State   Polymorphism in Actor Model   Two approaches to implement polymorphism 08.11.20 2
  • 3. Dynamo: Features 3   Key, value store   Distributed hash table   High scalability   No master, peer-to-peer   Large scale cluster, maybe O(1K)   Fault tolerant   Even if an entire data center fails   Meets latency requirements in the case 08.11.20 get(“cart/joe”) joe joe joe
  • 4. Dynamo: Partitioning 08.11.20 4   Consistent Hashing   Nodes and keys are positioned at their hash values   MD5 (128bits)   Keys are stored in the following N nodes joe Hash ring (N=3) 2^128 0 1 2 hash(node3) hash(node1) hash(node2) hash(node5) hash(node4) hash(cart/joe) hash(node6)
  • 5. Dynamo: Membership 08.11.20 5   Gossip-based protocol   Spreads membership like a rumor   Membership contains node list and change history   Exchanges membership with a node at random every second   Updates membership if more recent one received   Advantages   Robust; no one can prevent a rumor from spreading   Exponentially rapid spread Membership change is spread by the form of gossip Detecting node failure hash(node2) node2 is down node2 is down node2 is down node2 is down
  • 6. Dynamo: get/put Operations 08.11.20 6   Client 1.  Sends a request any of Dynamo node   The request is forwarded to coordinator   Coordinator: one of nodes associated with the key   Coordinator 1.  Chooses N nodes by using consistent hashing 2.  Forwards a request to N nodes 3.  Waits responses from R or W nodes, or timeouts 4.  Checks replica versions if get 5.  Sends a response to client get/put operations for N,R,W = 3,2,2 Request Response Client Coordinator joe joe joe
  • 7. Kai: Overview 08.11.20 7   Kai   Open source implementation of Amazon’s Dynamo   Named after my origin   OpenDynamo had been taken by a project not related to Amazon’s Dynamo    Written in Erlang   memcache API   Found at http://sourceforge.net/projects/kai/
  • 8. Process Design for Better Performance 08.11.20 8
  • 9. Two approaches to improve software performance 08.11.20 9   To process it with less CPU resource   Solved by introducing better algorithms   e.g. Binary search is used instead of linear search   To use all CPU resources   Issues identified in multi-core environment   Solved by rearranging process-core mapping   e.g. Heavy process and light process run on multi-core 1st core 2nd core boring… heavy process light process
  • 10. Two approaches to improve software performance 08.11.20 10   To process it with less CPU resource   Solved by introducing better algorithms   e.g. Binary search is used instead of linear search   To use all CPU resources   Issues identified in multi-core environment   Solved by rearranging process-core mapping   e.g. Heavy process and light process run on multi-core 1st core 2nd core work! work! heavy process light process Latter case will be discussed
  • 11. Diagram Convention 08.11.20 11   Procedural programming   Procedures are called by a process foo bar process foo -module(foo). -behaviour(gen_server). ok(State) -> {reply, bar:ok(), State}. -module(bar). ok() -> ok. process ellipse rectangle not process
  • 12. Diagram Convention, cont’d 08.11.20 12   Actor model   2 processes interact with each other foo bar -module(bar). -behaviour(gen_server). ok(State) -> {reply, ok, State}. ok() -> gen_server:call(?MODULE, ok). process bar process foo process ellipse rectangle not process -module(foo). -behaviour(gen_server). ok(State) -> {reply, bar:ok(), State}.
  • 13. Design Rules in Erlang 08.11.20 13   Some of rules on process design:   “Assign exactly one parallel process to each true concurrent activity in the system”   “Each process should only have one role”   from Program Development Using Erlang - Programming Rules and Conventions
  • 14. Processes in getting/putting data 08.11.20 14 Node 1 coordinator Node 2 Client memcache rpc rpc For clarity, details of architecture are omitted. store data coordinator rpc Choosing a node having responsibility for requested key
  • 15. Node 2 Node 1 Sequence in getting/putting data 08.11.20 15 memcache coordinator rpc coordinator store Client Blocked…
  • 16. Node 2 Node 1 Sequence in getting/putting data, cont’d 08.11.20 16 memcache coordinator rpc coordinator store Client Another client Blocked…
  • 17. Node 2 Node 1 Sequence in getting/putting data, cont’d 08.11.20 17 memcache coordinator rpc coordinator store Client Another client Accepted and… Blocked!
  • 18. Design Rules in Erlang, again 08.11.20 18   Another rule on process design:   “Use many processes”   Many processes are almost uniformly assigned to each processor by statistical effect   from Chap.20 Programming Erlang
  • 19. Processes in getting/putting data, again 08.11.20 19 Node 1 coordinator Node 2 Client rpc store data coordinator rpc memcache memcache rpc rpc coordinator coordinator For clarity, details of architecture are omitted. Spawning multiple coordinator processes
  • 20. Node 2 Node 1 Sequence in getting/putting data, again 08.11.20 20 memcache coordinator rpc coordinator store Client Another client Accepted and…
  • 21. Node 2 Node 1 Sequence in getting/putting data, again 08.11.20 21 memcache coordinator rpc coordinator store Client Another client Accepted and… Spawned It’s OK, but looks like overkill. Concurrency is produced by memcache module. Why it is reproduced by coordinator?
  • 22. Design Rules in Erlang, in final 08.11.20 22   Another rule on process design:   “Don’t spawn stateless processes”   Called as procedures from concurrent processes   Introduced by me 
  • 23. Processes in getting/putting data, in final 08.11.20 23 Node 1 Node 2 Client rpc store data rpc memcache memcache rpc rpc For clarity, details of architecture are omitted. Not spawned coordinator coordinator
  • 24. Node 2 Node 1 Sequence in getting/putting data, in final 08.11.20 24 memcache/coordinator rpc coordinator store Client Another client Accepted and processed
  • 25. Lessons Learnt 08.11.20 25   Process design based on calling sequence and process state   Externally called module   Must be spawned to produce concurrency   Runs as multiple processes if needed   e.g.TCP listening process, timer process   Stateless module   No need to be spawned   e.g. coordinator of Kai   Stateful module   Should be spawned for state consistency   Runs as multiple processes if possible   If a single process, it must be a terminal one (never call other processes synchrnously) to avoid blocking   e.g. database process, socket pool
  • 26. Process Relationship in Kai 08.11.20 26 memcache store data memcache rpc rpc hash members, buckets connection version coordinator sockets process ellipse rectangle not process state current version vclock config configs Relationships between stateful processes and other modules are omitted.
  • 27. Process Relationship in Kai, cont’d 08.11.20 27 store data rpc rpc hash members, buckets connection version sockets process ellipse rectangle not process membership sync with timer vclock current version config configs Relationships between stateful processes and other modules are omitted.
  • 28. Process Relationship in Kai, cont’d 08.11.20 28   “Lessons learnt” are almost satisfied   Externally called modules are spawned   As multiple processes if needed   e.g. kai_rpc, kai_memcache, kai_sync, kai_membership   Stateless modules are not spawned   e.g. kai_coordinator   Stateful modules are spawned   e.g. kai_config, kai_version, kai_store, kai_hash, kai_connection   However, some of them are NOT terminal ones   e.g. connection module calling config process, is potential bottle neck   “Lessons learnt” can point out potential bottle necks   Yes, connection module is just a thing!
  • 29. Advanced Issues 08.11.20 29   More concurrency may be introduced if needed   Design rules from “Lessons Learnt” can be applied locally   e.g. coordinator produces N concurrency for asynchronous calls   Referred to Web application servers in MVC model Web application servers Process Design from “Lessons Learnt” Concurrency is produced by Web servers, e.g.Apache Externally called modules Application is controlled by Controller of MVC Stateless modules State is managed by Model of MVC Stateful modules
  • 30. Advanced Issues, cont’d 08.11.20 30   Is blocking never occurred in pure functional programming?   In Kai, a process receiving requests waits for data to be replied   In pure functional programming, another process handles data to be replied?   Not straightforward for me… Blocking Req. Req. and socket Res. Res. and socket Kai Pure functional programming model?
  • 31. Polymorphism in Actor Model 08.11.20 31
  • 32. What’s Polymorphism? 08.11.20 32   “a programming language feature that allows values of different data types to be handled using a uniform interface”   from Wikipedia
  • 33. Polymorphism in Java 08.11.20 33   Interface   Implementation class interface Animal { void bark(); } class Dog implements Animal { public void bark() { System.out.println(“Bow wow”); } } Including no implementation
  • 34. Polymorphism in Java, cont’d 08.11.20 34   Abstract class   Concrete class abstract class Animal { public void bark() { System.out.println(this.yap()); } abstract String yap(); } class Dog extends Animal { String yap() { return “Bow wow”; } } Including some implementation
  • 35. Polymorphism Inspired by Interface 08.11.20 35   Interface module   Initializes implementation module with a name   Calls the process with the name   Implementation module   Spawns a process and registers it as the given name   Implements actual logics, which are called from interface
  • 36. Polymorphism Inspired by Interface, cont’d 08.11.20 36 -module(animal). start_link(Mod) -> Mod:start_link(?MODULE). bark() -> gen_server:call(?MODULE, bark). -module(dog). -behaviour(gen_server). start_link(ServerName) -> gen_server:start_link({local, ServerName}, ?MODULE, [], []). handle_call(bark, _From, State) -> bark(State). bark(State) -> io:format(“Bow wow~n”), {reply, ok, State}. Some required callbacks are omitted.
  • 37. Polymorphism Inspired by Interface, cont’d 08.11.20 37   How to use animal:start_link(dog), animal:bark(). % Bow wow
  • 38. Polymorphism Inspired by Interface, cont’d 08.11.20 38   Example in Kai   Provides two types of local storage with a single interface   Interface module   kai_store   Implementation modules   kai_store_ets, uses ets, memory storage   kai_store_dets, uses dets, disk storage   See actual codes in detail
  • 39. Polymorphism Inspired by Abstract Class 08.11.20 39   Abstract module   Defines abstract functions by using behavior mechanism   Spawns a process and stores a name of concrete module   Implements base logics   Calls the process   Concrete module   Implements callbacks, which are called from the abstract module
  • 40. Polymorphism Inspired by Abstract Class, cont’d 08.11.20 40 -module(animal). -behaviour(gen_sever). behaviour_info(callbacks) -> [{yap, 0}]; % abstract void yap(); behaviour_info(_Other) -> undefined. start_link(Mod) -> gen_server:start_link({local, ?MODULE}, ?MODULE, [Mod], []). init(_Args = [Mod]) -> {ok, _State = {Mod}}. bark(_State = {Mod}) -> io:format("~s~n", [Mod:yap()]), {reply, ok, Mod}. handle_call(bark, _From, State) -> bark(State). bark() -> gen_server:call(?MODULE, bark). Some required callbacks are omitted.
  • 41. Polymorphism Inspired by Abstract Class, cont’d 08.11.20 41   How to use   Same as an example of interface -module(dog). -behaviour(animal). yap() -> "Bow wow”. animal:start_link(dog), animal:bark(). % Bow wow
  • 42. Polymorphism Inspired by Abstract Class, cont’d 08.11.20 42   Example in Kai   Provides two types of TCP listening processes with a single interface   Abstract module (behavior)   kai_tcp_server   Concrete modules   kai_rpc, listens RPC calls from other Kai nodes   kai_memcache, listens requests from memcache clients   See actual codes in detail
  • 43. Lessons Learnt 08.11.20 43   Two approaches to implement polymorphism   Inspired by interface   Simple   Not efficient   Actual logics have to be implemented in each child   Inspired by abstract class   Erlang-way   Efficient   Abstract class can be shared by children
  • 45. Outline   Reviewing Dynamo and Kai   Kai: an Open Source Implementation of Amazon’s Dynamo   Features and Mechanism   Process Design for Better Performance   Process Design Based on Calling Sequence and Process State   Polymorphism in Actor Model   Two approaches to implement polymorphism 08.11.20 45
  • 46. Kai: Roadmap 08.11.20 46 1.  Initial implementation (May, 2008)   1,000 L 2.  Current status   2,200 L   Following tickets done Module Task kai_coordinator Requests from clients will be routed to coordinators kai_version Vector clocks kai_store Persistent storage kai_rpc, kai_memcache Process pool kai_connection Connection pool