Player is loading...

Embed

Copy embed code

Transcriptions

Note: this content has been automatically generated.
00:00:00
to to start everything works whether yeah okay so hello my name is other rescue thank you very much
00:00:07
for coming um i would like to do today a
00:00:10
comparison between anyhow 'cause i. o. and the more next
00:00:14
in the future of concurrent programming um so would there would be a couple of introductory slides and then we
00:00:20
will enter proceed to the code i know it's late uh um but i hope the code will wake up
00:00:28
so and
00:00:30
what what do i mean by concurrent programming in two thousand nineteen well when we
00:00:36
wants to do something that processes they thought concurrent
00:00:39
temporal we typically have to define a couple of processors
00:00:43
that work on the data that communicate with the whole all over the network that three some
00:00:49
data from the database and so on so for the question is how do we define this process
00:00:55
and that's a couple of hunters out there especially in this cologne and and he sort of fiscal i think head
00:01:01
quite and a lot of success and uh the the scalability of the language allows
00:01:06
you to the find some really nice sleepy eyes for defining the yeah these uh synchronise
00:01:12
concurrently running processes in a nice way and in a way that makes the programs
00:01:18
yeah it's easier to write and also have less bucks as a as a as an effect
00:01:24
um so when they what when wondering how to describe how to
00:01:29
define these con commentator running processes we have a couple of questions
00:01:33
once the right so the first thing is how do we compose processes right
00:01:38
so we typically want to run a couple of those maybe concurrently maybe in sequence
00:01:42
so the first aspect of they guys how does
00:01:46
it eh and how composing a couple of processes together
00:01:49
right processes also typically communicate with each other so ever important aspect is
00:01:54
how eh one process can communicate eh and the years can send data to another process
00:02:00
how kind of communicate that it's done all that it needs more they tell that it's needs to spawn type processes and so on
00:02:07
finally the hardest thing in concurrent overall
00:02:11
programming is managing state right we cannot access
00:02:15
this same and mutate more important in the same state for multiple
00:02:19
threads so this state needs to be somehow protected try so that this
00:02:24
always on a single writer and to to to to our product that state
00:02:30
yeah its own scar and all of the libraries that we will look at an
00:02:36
constrain side effects in some way and and all of the
00:02:40
side effects are always wrapped in some kind of a container
00:02:43
and these containers actually allow you to define and describe this process is in a flexible way
00:02:50
and they allow you to work with the values which you can then manipulate and um
00:02:56
and and uh the the values at the means through which we
00:03:01
we a creative process right so these containers differ from library to library
00:03:07
so for example in that colour and we were mostly work with futures
00:03:12
and a future is an eagle or running computation it's important that it you go
00:03:16
we'll see later why uh so if you change the competition it's already taking place
00:03:21
right on the other hand we have various lazy implementations uh in
00:03:28
it's such as task silos and so on and these describe
00:03:32
the computation which will take place once we run it right
00:03:36
so on one hand we have the eager futures and on the other hand we have the lazy tasks ios and so
00:03:44
okay so this may sound abstract but we will see concrete code in a second
00:03:49
so in our example that we we are we always need some kind of an example and
00:03:55
we will pretend that will have a number of devices yeah these devices would
00:04:00
be laser cutters that's how will they would be called in the code so let's
00:04:03
imagine that we have a series of laser cutters right and yeah it's such a
00:04:07
device is this cars resource uh to which we have to protect access right and
00:04:13
we want to send list of commands the laser cutter so you can imagine
00:04:17
that list of common describes how to animal cut out the cat shape a dog
00:04:21
shape or whatever so we want to send and a series of steps to each
00:04:26
of these the of uh these devices and and of course we must ensure that
00:04:31
only one thread only one process sense this comments to a laser cut
00:04:36
at a time right so we were communicating we you'll with these devices
00:04:40
using a connection object right that's also quite similar to like a database connection here will be in a device connection
00:04:48
so this device connection object is the state that wants to
00:04:51
protect in our processes right and of course we can use
00:04:55
multiple different laser cutters in parallel but we want
00:04:59
to protect the connection of each so that it's used
00:05:03
by a single pauses okay so we have a number of processes
00:05:07
which actually communicates with devices and we'll have a coordinator process which eh
00:05:12
worse were the against or state to the state would be
00:05:15
the list of free devices of free connection that you might use
00:05:19
and if there are no free devices it was also the buffer of jobs
00:05:22
to run so web about reviews of comments that eh that's supposed to be on
00:05:28
so and when we look at the code and so the goal here is not to become familiar with a. p. i.
00:05:36
n. because that's i guess i is best done you know at home when you have the i. d. and so on
00:05:41
yeah it just to get a feeling of what are the main differences between
00:05:46
and the the archive approach and the more functional approach it's a right so
00:05:52
when looking at the a. p. i. take a look at how does the infrastructure code so how does the code that
00:05:57
we used to this to the to the find the processes interfere with the
00:06:01
let's say core business logic right if it's programmer friendly so is it easy to
00:06:07
to read and understand right if you showed a colleague would eh would they understand it
00:06:13
yeah yeah i noticed how the description of a problem is separated
00:06:17
from the evaluation of the actual process right it this would be an important difference
00:06:24
also not is what is good and what is what what is lazy that i mentioned before as well
00:06:30
and okay so before we actually to jump to the coda short introduction so that you know who's stalking corrupt
00:06:38
yeah the i'm one of the co founders and a soft landing it's optimal
00:06:42
yeah software and we are consulting and development a company
00:06:46
with a special lies and skylark are after cassandra other technologies
00:06:51
yeah we had companies scale of that businesses introduce
00:06:55
functional programming oven sourcing data string pipelines and someone
00:07:00
and i'm also working on a couple of open source the projects such as as
00:07:04
the t. v. it appear a quick glance and and a couple of others okay so
00:07:12
uh yeah that's the first example that the that we
00:07:16
will look at is eh will be using data so there
00:07:20
we would be using i cut typed here so you
00:07:22
might be familiar with the traditional act approach which users and
00:07:28
better and typed actors right and the uh the messages that you send an actor always on tight
00:07:34
so here we are using a cut type which is an evolution of the name of the of the framework
00:07:40
and so it does as a short reminder and an
00:07:43
actor eh which is the basic building block of everything in
00:07:47
a car and act or is the lightweight process and which
00:07:51
contains some state and that state is guaranteed to be protected
00:07:55
so it will always be accessed a by a singles right at the time
00:08:00
and the way you can communicate with an actor is by sending it eh it messages
00:08:05
and this message is also got a uh i'll uh also guaranteed to be processed a a one at a time right
00:08:12
so the actor is allied with process and it got it encapsulate some n. or something
00:08:18
okay so let's let's look how can we implement our laser cutter example using using okay so as i said
00:08:24
we were have and device connection class right so we pretend that we had a number of laser cutter devices
00:08:31
and we communicate using a and b. communicates with them using these instances of the
00:08:36
device connection prospect so that that's like a database connection here we have otherwise connection
00:08:41
and this class has this in go mad thought eh called
00:08:46
uh called run command right we can send the command
00:08:49
like go forward or turn right then to the device
00:08:54
and the device will execute that comments right and exacting in the command
00:08:58
will take some time so uh we have an as a synchronous interface so
00:09:03
we get the back of future right that which i will be complete
00:09:06
once the device completes eh the comment right here because we're pretending we're not
00:09:11
we don't have a real devices so instead of doing network io to
00:09:15
the device we we only do an a screen io printing something to the
00:09:21
to the console right so here he is our side effect of actually sending sending the common thread and in some
00:09:27
cases things will end up with an error so an exception would be thrown and the future would be fate right
00:09:35
so that's and that's our uh that's the interface to to the device that we would be using an
00:09:42
so first let's and and and his that type ideas which is a
00:09:46
list of commands that will be sending one by one to the device
00:09:50
so first let's the fine yeah yeah the the behaviour of a process eh which will manage a single
00:09:58
and a list of commands is sending as single is of comments a single device right
00:10:03
so that's a process to actually complete as single a singles of common so we will define the laser
00:10:09
a couple process it will take the parameters the first parameter is the commons it to execute
00:10:15
eh the second parameter is the device connection the that's
00:10:19
right and the result of this process would be a behaviour
00:10:25
behaviour is eh in eye contact describes what
00:10:29
the actor should do right so that's a that's
00:10:32
a description of the behaviour of single actor okay what's important is that it's a lazy construct
00:10:38
it's a it's a it's a data structure which only describes what the actor should right so
00:10:43
by creating a behaviour we don't actually do anything except a locating some data structure and he
00:10:49
right it's on a description nothing happens when you created only once you actually interpret what once
00:10:54
you pass it to act that it will create a an actor which with that specific behaviour
00:11:00
so the behaviour is parameter tries with with a single type and they it it that's the type of the messages which
00:11:06
we can send eh which we can send the tower actor
00:11:10
so here we will be sending two types of the messages
00:11:15
and so we are type safe so we always need to define a closed set of messages that we can actually
00:11:20
send sense to our process lower actor so with the
00:11:24
find a suit yeah straight and make the cut that message
00:11:32
and the the for as to kind of message will be next common
00:11:39
and the second will me there
00:11:43
okay so when our act or receive the the next command a message it means that
00:11:51
the device has finished eh exhibiting the last comment and we and we should eh exactly the next command right
00:11:58
if is the actor receive the error message it means that there's been
00:12:02
some error in the device and we have to abort the whole process
00:12:06
okay so the behaviour of a single laser cutter process would be a would be accepting these messages so how
00:12:12
can we create eh this behaviour so there's the behaviours companion on the the behaviours object and i caught that
00:12:19
which contains factor method to defining and number of a behaviour so one of these behaviours is received message
00:12:26
and a receipt message describes the behaviour so to create a data structure would describes the behaviour
00:12:31
which specifies what should the actor do when her message
00:12:35
arrives on its mailbox right so we can receive tool and
00:12:40
the types of matter of uh messages the faces
00:12:43
next command this second is an error right okay
00:12:49
so now what should we do when the actor receives an x. common
00:12:53
message right so we should take a look if that any comments left
00:12:56
to to process right so we take a look at commands if that uh it yeah i there
00:13:01
can be no more comments to process all that can be a single command and some other comments
00:13:09
okay so let's take it one uh it was that at the time so what if there are no more comments
00:13:15
to process right then allow comments the process we always have to somehow
00:13:19
stop the whole laser cut the process right that's the finish of the process
00:13:23
we have executive all the comments so what we have to do is we have to somehow free of the connection
00:13:30
three the connection right so we have to tell the coordinator that this connection like is actually free then we have to stop
00:13:37
the process so how do we do that but if we
00:13:39
look at this signature of they receive and of the receive message
00:13:46
and i thought yeah it actually it takes a have a a function which a
00:13:54
depending on them on the received message a returns the next the behaviour of the doctor
00:14:00
right so it's similar to the it to the f. s. m. yeah the state machine act
00:14:05
or which you could also would do an eye contact so the our description of our behaviour is
00:14:10
receive a single message from the mailbox and then decide what to do next like what's
00:14:15
the next behaviour of the act right here the next behaviours act would be quite simple
00:14:20
behaviours that stopped means it's stop at a stop the process
00:14:26
okay so now uh in if there's an error we could i will
00:14:29
actually do the same yeah we'll just print line than this and there are
00:14:35
and we return behaviours stopped
00:14:39
and one okay so now the and we also have to feed the connection away
00:14:45
and so now and the last case what do we do if there is a common technique where we take the connection
00:14:53
the only thing that we can actually do and we run the commons right run the command and
00:14:57
at that point because we get a future right here we we get back a future so that's
00:15:04
a process which already is running in the background eyes is is an eager running side effect right so
00:15:10
and in our lazy description of uh the behaviour week i can we we can actually do some side effects
00:15:18
and he yeah that's uh that's one of the side the fact that
00:15:20
we do here right um so we run the we we run the command
00:15:26
yeah yeah but then once the command this company it we have to tell the actor that we it it's it should
00:15:31
process the next message so what do we do we say
00:15:33
that can compete that two cases yeah yeah it can either
00:15:38
and send it by the run command right it can either compete with the success or it can and the phase
00:15:46
okay so that it ends with this access what we have to do is we have
00:15:51
to somehow obtain the self reference of the current process so we have to drive the self
00:15:57
and i'll send that was that was the next common
00:16:00
message right here similar we have to send our service
00:16:05
the an error message right now the problem is we had we take the self reference from right
00:16:10
remember that we only creating a data structure description of how the actor should behave right we have
00:16:16
we don't actually live in any kind of context where from which we can take this self reference right
00:16:23
so we actually have to include in our description the fact
00:16:27
that he wants to extract the current context in which we're running
00:16:31
and we can do that using the behaviours that set up without
00:16:34
passing in the type here and otherwise type inference is lost so
00:16:43
we wrap how we receive message behaviour in another behaviour which
00:16:46
with says extract the current context in which are when it
00:16:50
which guy running and receive the next behaviour of the actor
00:16:53
which is receiving a message right and here here we actually get
00:16:58
yeah yeah here we actually get and the self reference from the context right it's a red that's good
00:17:05
because we still have to return the next behaviour of the actor right so what we did was we said if there's a command
00:17:12
actually run it wow run this as a side effect right so that's the side effect
00:17:16
it's something happening in the background but what should the actor the now with it should again
00:17:22
receive the next message right so when the future companies that we actually get the next message right
00:17:27
so what we have to do is we have two records recall the laser
00:17:30
cutter method and with a shorter list of a commons than the same connection okay
00:17:37
and that's it um okay so far so good well we still have
00:17:42
one hole here we have to somehow free of the connection right so
00:17:46
once they we have executed all the comments in sequence right we have to say
00:17:51
to the coordinator that we are done so to do that yeah we were and
00:17:56
actually the eh the core data would be another would be a another actor so i would uh that's the
00:18:04
copy is the messages over here and so
00:18:10
and the coordinator uh will be an actor which we receive messages of type coordinator message
00:18:17
and we can send two types of messages to the court later the first one is that
00:18:21
the connection is free and the second is that some comments should be schedules to be run
00:18:27
by the coldness right so here we we need to add an extra parameter which is a reference
00:18:33
eh to the add to the course later actor and coordinator message okay
00:18:40
right so now our laser cut the processes parameter tryst with the reference
00:18:45
to the court to to the call to the coordinator actor right um
00:18:50
we have to pass it here as well on a coordinator okay and he yeah we can
00:18:57
actually now around the side effect of freeing
00:18:59
up the connection and that simple a coordinator send
00:19:04
uh my connection free of connection right and we
00:19:09
copy that in case of an error as well okay
00:19:14
so now we have described and the process of a single laser cutter running as a a list
00:19:21
of comments right so we have a list of comments which we run in sequence by our and
00:19:26
yea by sending them to the connection and we create a and description
00:19:31
of the behaviour right these are all eh that's the the the cell
00:19:36
data structures which we create and then they will be interpreted by the
00:19:39
actors system and so now what we would do is we will actually
00:19:44
implemented the coordinator using the function approach so i would just copy
00:19:49
and i would just copy the the the coordinator called using
00:19:53
a cover here because we don't have that much time unfortunately
00:19:56
it's very similar to the process we have seen before and it it
00:20:01
to uses the same constructs it the coordinator holds state as i said
00:20:06
the first element of the according to state is the the list of free connections
00:20:10
right and the second element of the correlated state if is the buffered list of comments that
00:20:15
has to that have to be run in the task of the coordinator is sparing up every connection
00:20:20
with a list of with a list of comments right so the only important thing really that happens in the coordinator is over here
00:20:26
so once we actually have a power so we have every connection and we have a list of comments
00:20:31
right what we do is we create a child process is we create
00:20:35
an actor using as specified behaviour right so first we created the behaviour
00:20:41
we invoke the laser cutter method over here right so this a create a description the
00:20:46
behaviour and then we pass it to the spawn i thought which actually creates an actor
00:20:51
with that behaviour right so that actor will actually go step by step and see what's little
00:20:55
now i that's my behaviour so i will do that right and so on and so on
00:20:59
because the each uh each behaviour we resides in in a new behaviour that actual should actually then do
00:21:06
okay um and then we kick start the whole process using the the next
00:21:10
command that so we can and so that you can see that it actually
00:21:14
enter works we can have some example data over here
00:21:19
so uh yeah what we do here is that we create an actor system so an actor systems like
00:21:25
us red ball and button in in i can't type that also nice to have a top level actor
00:21:31
so 'kay the doppler actor is the coordinator again we created description we pass it to the actor system and actor some
00:21:37
creates an actor which we execute that that behaviour we create
00:21:41
some device collections right and we we run the whole thing
00:21:45
so we may see it actually works we're sending then we as scheduling a couple of lists of comments to run
00:21:52
and yeah the well despite the fact that we have created that are spending to the console so we can see that this is actually being run
00:21:59
and first by the second connection then my the first connection right the l. c. one or c. two
00:22:05
then there's an error or because there's little turtle right so we we we you
00:22:10
haven't or or hear about things continue running and we're processing other things as well
00:22:16
okay so that's back example so now let's move to the second one um
00:22:23
so um despite the title said that i would actually to compare both more nixon's
00:22:30
io but that would take too much time so i decide on it to does io
00:22:34
however in the scope of this example the code musings
00:22:37
io and the code using more next would be almost identical
00:22:41
you would have to switch io to task and it would be more or less the same so the
00:22:45
the thing question i think the important difference between via code in my next coat is that ins io
00:22:52
errors also typed and them on except i will show you exactly where that place is so so that you know the difference
00:22:58
between one extends out in the scope of this example right them
00:23:01
anymore differences buttons example that's the one that would be actually visible
00:23:06
okay so now we're moving away from the future well right
00:23:10
to a more functional worked in the functional load everything is lazy
00:23:14
right before we had lately behaviours but if you just by running early right here everything is lazy so yeah yeah
00:23:22
we have the same device connection class with disk which day is used as an interface for the connection
00:23:28
and we have the same run commandments also would accept a common
00:23:32
and what it returns is an i. o. type right in iowa type is
00:23:37
where yeah it's it's like a future in some ways but in more ways it's
00:23:41
not like if you just so and i will type is a lazy description of
00:23:44
a side effect so and again it's a data structure which when actually interpret that
00:23:50
we run decide the facts right so a future is the running eh is the computation running in the background
00:23:57
in an i. o. is a lazy description of what will happen when we actually exactly the side effect right
00:24:05
so here we have like a functional interface to our uh to have
00:24:08
it to our device and the effect is the same right we wrap it
00:24:13
in an aisle constructor so that's that would be invited lazy lisa by
00:24:17
name parameter and the effect is the same just printing to the council right
00:24:22
so uh that's again the same again the important difference here is the type arrows right
00:24:28
and if in the in the in the future case and then the more next case
00:24:31
if there's an arrow so if they if they a i think there's competition face
00:24:37
the errors always type this as a as a
00:24:40
as an exception at the problem right in his io
00:24:44
they make a distinction between errors that you expect to happen so
00:24:48
arrows from which you can recover from so here we actually expect that from time to time there
00:24:53
would be a laser context that's right and a of course you can always still another type of exceptions
00:24:59
but these are considered to be bugs ride height desires which you actually do not expect and you cannot recover from
00:25:06
and these these type the these arrows you expect our and attacked
00:25:11
okay so let's first again implement the
00:25:16
in the process uh it off of a single laser cutter and the single is a cut the process
00:25:24
so we define a laser cut the process again experiments right by
00:25:27
the same things a list of commands and the connection uh to use
00:25:31
it will return at description of a an offer process
00:25:36
which were i the throw a a basic out exception originated
00:25:41
okay but now we can do something a bit different so we have the list of commands that we have to that we have to run right
00:25:50
now what we can do is we map over this list like you map of
00:25:54
a this quite commonly probably and we take we can mark and create a list
00:25:59
you can map using the one common method right so that we had the list of
00:26:02
comments and what we get is a list of descriptions of how to send the comment
00:26:08
to the device right we can do this because these descriptions are lazy
00:26:13
if we did it with a future they would all be sent at once right because we would create a list of features
00:26:18
and the futures is running computation so all the comments would be sent to the base that once and it it would blow up
00:26:24
right so here we only creating a list of descriptions and that's the important difference
00:26:29
and and we can do it safely right it's not what we want
00:26:32
to do is want to say run this list of comments in sequence
00:26:37
right that's a common thing so they actually have an operator for that call collect all the collect all takes a
00:26:43
list of descriptions of side effects and returns the side effects
00:26:47
which which will run the side effects in sequence so and
00:26:52
then we have to discard the the results so we get the unit and that's the implementation of holidays
00:26:57
a got the process right it's quite significantly different from the actor that we have the find before okay now
00:27:06
once we have that and it's actually implement the the coordinator
00:27:11
great so our coordinator will have an list of initial connections
00:27:18
and the voice command and the vice connection okay
00:27:22
and it will return as a description of a process which cannot fail
00:27:27
so we don't expect it to fade with any kind of errors and returns a result
00:27:31
which is more like a technical thing is so that you can actually communicate with the process
00:27:36
so don't worry about that okay so no how could how how can we implement the coordinator so
00:27:42
and in act are we actually have a single template a single blueprint financing
00:27:49
for this process right each process that we define an actor is an actor
00:27:54
yeah which share with which we can communicate using you're using messages right
00:27:59
it's a very useful template uh very useful blueprint but is that a
00:28:03
it's not always the on on saturday as as we have seen right
00:28:07
for example they laser got the process over here didn't really need
00:28:11
an in box didn't really need the whole actor decoration right and
00:28:16
so uh in the in the in the dial you kind of have more
00:28:20
flexibility in akron we only have this one a blueprint that you always use
00:28:24
that may be able to think that might be a bad thing right because sometimes if you're a constraint is actually easier to do things um
00:28:32
in the in is i we have more free don't which means we can implement processes like we
00:28:37
have done here with the laser cutter right in every second grade but sometimes actually have to a
00:28:43
we have to kind of implement an actor right so in case of a of a coordinator we actually do wants to have
00:28:49
a single process which has encapsulated state and with which we can communicate using by
00:28:54
sending messages right and in our car this is but then this template this actor
00:29:00
and this message just about this but then he yeah we have to explicitly create
00:29:03
a cue which would be the in the box use to communicate with the act okay
00:29:09
sometime in the coordinator we were actually defined to mess thought tool men so
00:29:13
it's the first one with the scrap the process what should the corn it'll do
00:29:17
and given some state of a free connections and
00:29:21
waiting messages so it we have a couple of parameters
00:29:25
the first one is the in box so that's the way to communicate with the process right
00:29:29
in a car that's like for the better of by the framework here we have to do it
00:29:33
and here we have to explicitly right that we need a queue of coordinator message
00:29:40
okay the second process will be the for the the connections
00:29:45
that are currently of free that's a list of the vice connection
00:29:51
okay and the this third parameter is it
00:29:55
that but to the to the waiting comments right
00:29:59
okay and it's a description of a process no arrows and the unit
00:30:04
so what we do again is we take a look at the connections and the and the waiting jobs
00:30:10
right and now we have two possibilities either we haven't match so there is a free connection
00:30:17
concord free connection and some other connections and today we had
00:30:23
a if i wait first waiting job persuading drop and other waiting
00:30:29
right we button much on the connections and waiting jobs so
00:30:34
well in that case we have like it better right we have
00:30:37
every connection we have a job to run so we can actually start the process which actually does that so what we do
00:30:43
is we call the late a week we call the laser cut
00:30:47
them i thought yeah yeah we pass it the the the the
00:30:51
any comments to run and the connection to use right so what do we do now what
00:30:57
we have a description of the process but it's so some arrows right and here we need we
00:31:01
need to handle all of of uh all arrows so what we do is we actually handle the
00:31:05
arrows over here so we use the catch all communicator and say that if there is a and
00:31:14
like the cut exception we would uh as print line
00:31:20
and something to the console right e. a. okay
00:31:27
okay so you may notice that i am wrap this and then you iowa
00:31:32
you io is an io with the first type parameter equal to nothing so
00:31:37
ins io every side effect needs to be controlled and
00:31:41
every side effect nice vector wrapped in the container right
00:31:45
and act are we could have run any side effect this part of the anna of uh handing the message
00:31:51
he every side effect has to be but it's not enforced by the compiler and
00:31:56
but the idea is that every side effect is managed and is wrapped in the in and i know they that okay
00:32:02
so uh and eh we had a laser cut the process description some known what
00:32:07
we what we need to do is we need still to free up the connection right
00:32:11
note is that we don't free the connection over here in anyway
00:32:14
right so what we need to do is a we need to always
00:32:18
if we have the connection regardless if it is the the later got the process and it's
00:32:23
a sex full with an hour right so again there's a common it over that called ensuring
00:32:29
and ensuring takes an effect run always when the process finished right
00:32:34
so the fact that we want to run he has we actually wants to send
00:32:38
and let's say we'll believe it that's not like again and that's how
00:32:43
we more those things here in our code but that's not something uh
00:32:47
enforced by the framework uh we're creating an effect which was actually put a message on the
00:32:53
eh on the in box and the message would be connection free
00:32:58
right connect and the the the free connection um
00:33:04
okay so i can the ensuring over here it takes a finalise that
00:33:08
with the with which is also an lazy description of a side effect right
00:33:12
every every side effect is wrapped in an io right so here we're
00:33:16
gonna have an io and because we're using a cue implementation from dial
00:33:20
the offer my thought actually when we called off and i thought it doesn't actually put anything on the q. it returns a description
00:33:27
which when executed well we'll put the thing on the q. okay so everything is lazy but things so that
00:33:34
so i think so that lazy approach we can actually create this
00:33:38
process and and which it step by step right so uh in
00:33:43
this description over here right it's not something that's running
00:33:48
so we can uh a safe and without feel like enrich it in my in multiple
00:33:52
ways it's it's on a description which once we pass it when evaluate the will run right
00:33:59
okay so we have a a we have freed up the resources so one last thing that we need
00:34:04
to do is we actually need to run this in the background right because that guy in the correlated process
00:34:09
and we now have to say that we have greater than any description of the process and run this in the background so we create a four
00:34:17
now we we used before combine it right so what
00:34:20
this does is it creates in your description right which says
00:34:25
i have i i'm i'm wrapping this description we hear one
00:34:30
right and when you interpret this fork and run this description of the process in the bigger okay
00:34:39
and find a we need to do something in the main call they the process and what we do in the
00:34:44
medical that the process is we call and they receive method
00:34:48
which we right in the second other connections other week okay
00:34:55
and okay and that's it and if there is no
00:34:58
match then we simply call receive in box connections waiting
00:35:05
and these to the service event in a next method um the jury recursive so
00:35:10
the receive method actually has the same signature and it's a bit simpler receive
00:35:21
okay so what receive does is it takes the inboard with the we take the in
00:35:25
box we take the first message from you take the first message from the in box
00:35:30
and now depending what the message it is it can be
00:35:34
either connection the free air connection then we call next in box
00:35:40
we added to the list of free connections and we decide what to do next
00:35:46
or it can be run comments
00:35:50
comments next in box connections comments
00:35:58
like okay like checked and finally we need to bootstrap the whole thing so we
00:36:03
create an in box we create an unbounded yeah oh that's not what i wanted
00:36:10
and we created an about the in box which will hold messages of that correlate the message
00:36:16
we create a wheat kicks out the process so we create a receive process
00:36:22
with the initial connections and awaiting methods and now we want to run
00:36:26
this process in the background so we use the fork combine it or
00:36:31
and we would uh coordinators soaked in box work okay so that's the description
00:36:38
of our coordinator process by this description what it will do it it's fibre
00:36:44
uh what it will do things uh it will create an unbounded q.
00:36:49
then it would create at this it would create the receive process and it will run it in the background to
00:36:54
return a control to the parent process which called which called
00:36:59
so now let's copy yeah uh some test code over here
00:37:03
and so uh in our test code what we do is we have a default one time so
00:37:10
that's in actor systems we have the we had it in an actress or we had actor system
00:37:15
which was like the default interpreter for behaviours right so it took a behaviour in that it returned
00:37:21
an actor so here we have it at the a default one time so what it does it takes a description of a process
00:37:27
and it interprets this process right step by step right each time we use a combination over
00:37:33
here so when we call ensuring when we call for creating your description so in your data structure
00:37:40
which is bigger and bigger right but that contains instructions to what
00:37:43
to the run time should do when evaluating this this this the process
00:37:49
and right so in our on time where we create the cord radar and then we use the the in box which is
00:37:54
returned as a as the results actually send some comments and
00:38:00
to our uh to our process so we can actually run this
00:38:05
and and yeah the the the the output is fairly similar right so we have an
00:38:11
some uh uh some common the process by the first connection some comments offices by the second connection
00:38:18
and there's the error as as we have seen before so this
00:38:21
works more or less what is the second order is probably different okay
00:38:27
so that's the that's the code and so as for and make the main features
00:38:35
where we have a and the main differences between the the
00:38:39
the the with the future stack and the functions like let's say
00:38:43
so and in i can i can type what we have
00:38:45
seen is we have descriptions which eh we we we have behaviours
00:38:51
which also descriptions that lazy descriptions of how an actor should behave that tight
00:38:56
so we have to explicitly specify the type of the messages that consent to the
00:39:01
and it to the actor right however this side effects that we
00:39:06
and that we execute and as part of vector behaviour all these are
00:39:11
usually future base so that you got it evaluate right so inaccurate type
00:39:15
you have got kind of a mix we have the lazy behaviours and
00:39:17
eager futures right both in more next and then dial and then cuts effect
00:39:23
everything is based on lazy data structures which i evaluate it only
00:39:28
once a once we actually in what was actually interpret them right
00:39:32
so this also means that when defining these processes using dial or a a more
00:39:37
next we actually have to define one big process which describes all this side effect
00:39:42
right so we cannot eh we eh you cannot describe part of the process and then
00:39:48
and describe the second part of the process separate always have somehow connect them so that they are part of the single evaluation
00:39:55
um all these approaches are type safe and i the difference being
00:39:59
that in the aisle also the the the expected errors uh type
00:40:04
right in the eye kind more makes a these are types to throw boo
00:40:09
yeah i was also i also or already mentioned the side effect life cycle of call backs is also
00:40:15
a quite important so how to handle errors how to handle final years so it i cousins typically done
00:40:21
we we have then it kind of in in the manual way so if there was an error we does we we we we well understanding and
00:40:27
and i or message another way in which you can try to do that is using supervisors so we can create and i
00:40:34
uh when you create the try doctor can supervisor then be notified
00:40:37
when the actor when the tide actor is terminated however the the
00:40:43
and the behaviour uh some of the things that you do when you receive a life cycle come back this needs to be synchronise right
00:40:50
and ins io and then the more next everything is based on ios which eh again now the so
00:40:56
it's the same construct right to the same description off of a side effects and also an important difference
00:41:04
is that an act that we have the single blueprint of uh i think those browsers
00:41:08
and which is actors and and again that might be a very good thing because it simplifies the way you
00:41:14
think about i think responses right is always an actor and you always know that you are going to communicate with it by sending messages
00:41:21
ins io and then ma next we have more flexibility
00:41:24
and but you know with more power comes more responsibility so
00:41:30
and yeah we have looked on lead them very small parts of all of these libraries so a a a
00:41:38
i cry is much more than just the actors right we have
00:41:42
like a persistence for events sourcing market clustering at our remote thing
00:41:46
an actress streams and in more next we also have an attractive streams and implementation
00:41:52
and quite tight integration with with cats effect and
00:41:56
in desire we have software transaction memory we have execution
00:41:59
traces and we have a d. s. l. for the finding reach rice and also got integration so uh
00:42:07
this down political systems better on this libraries we have only looked at the
00:42:11
tiny fraction so depending on what will actually wants to do and you should
00:42:15
it probably the probably look at at at the whole add ons and that are that are and available
00:42:23
um okay and that's a that's all i had if you'd like to uh take
00:42:27
a look a more in more detail and this block over here contains a detailed comparison
00:42:34
of is collide v. eight audio which is that was io and monica not got tight
00:42:39
with the a couple of code examples so it's like it's report and it's it's report blogger
00:42:46
and the court for the for this presentation is online and
00:42:50
the and yes pieces that was stand you can subscribe that too
00:42:54
and it was kind of times uh oh you can win yeah well you can read the
00:42:59
subscribe to yeah try to win and try to and and and and and try to get out
00:43:05
and buy the party and and the yeah yeah it have any questions i'd be happy to take some
00:43:24
that would be hard questioning why things are the quick presentation on
00:43:29
and things for giving the pocket example i think you have shown
00:43:34
all with blue collar perfect example for how i
00:43:39
think actors should not be used for process use
00:43:44
on the you could measure was approved example for how to should be used but full prophecies let me go
00:43:51
it was all too cumbersome as we have seen all these load was one line or handle
00:43:56
you local actor or processes little process was like twenty lines and some new messages all round
00:44:03
i think there are other ways using all the streams or maybe even if you choose you can probably or your you could somehow make them
00:44:10
right yeah you then have the few who still trying to make a really huge are not eager you actually end up
00:44:15
doing a very simple version of an io because you retire
00:44:19
a rubber which contains a lazy about it it's yours right
00:44:22
so you can as well be might yeah that's yeah yes i agree that i cuss trees would fit here as well yeah
00:44:27
yeah but if you if you want to do it with like you know
00:44:31
your actors and uh i guess that's that that's where you had you will
00:44:35
so so we have all seen the actors or models suitable to build all
00:44:39
the user like those a lot walk about two newsletters for it wasn't thanks i
00:44:52
yeah you seen that oh you're use more powerful than going back all
00:44:58
i mean like more has more power but if you look at orchid room
00:45:02
an architect reagan does change your will remain to do next absolute seems like
00:45:08
extremely powerful so you can just wall going to next to the you will be from you you're
00:45:13
in complete into program reached up right when i i wouldn't say that is i was more powerful really
00:45:20
and like maybe something's gonna be expressed in more concise
00:45:24
code and eh the whole approach when you switch to
00:45:29
thinking in terms of lazy effects uh instead of eagerly right uh if you're running effect well this
00:45:35
changes the way you go the bit right but i wanna say it's it's more file for us like
00:45:40
i mentioned it to combine like especially the constraints like a clustering and so on so that's also quite
00:45:44
a powerful powerful makes as for the changing behaviour and what yeah i actually that's that's estimate right because
00:45:51
in both examples what you do is you describe as single step of a process
00:45:55
like uh the uh the behaviour is a single step i receive the message and
00:45:59
that's a single separate and what that what by the next right and so that's kind of changing behaviour but
00:46:05
in a controlled way because you always call yourself records through this all mutable state or anything like that and
00:46:11
in the file example we kind of did more or less the same thing right because we also we also
00:46:16
yeah that was also the recursive a step over here right uh
00:46:22
well we call the next method which describes a single step of what should we do with the state
00:46:27
and the next step is described by every recursive call underestimate so these are
00:46:32
quite some uh they oppose implemented in a recursive manner both both both coordinators
00:46:38
and if a if you actually look at the code of the colour over here like even if
00:46:42
you look at the shape itself it's quite similar right we have the next and receive my thoughts right
00:46:48
and here we have the two cases of area of a week of a recursive receive call
00:46:55
one is exactly the same as we have here right same of a same with the pending of a single message
00:47:02
okay
00:47:05
uh_huh
00:47:07
oh

Share this talk: 


Conference Program

Welcome!
June 11, 2019 · 5:03 p.m.
1574 views
A Tour of Scala 3
Martin Odersky, Professor EPFL, Co-founder Lightbend
June 11, 2019 · 5:15 p.m.
8337 views
A story of unification: from Apache Spark to MLflow
Reynold Xin, Databricks
June 12, 2019 · 9:15 a.m.
1267 views
In Types We Trust
Bill Venners, Artima, Inc
June 12, 2019 · 10:15 a.m.
1569 views
Creating Native iOS and Android Apps in Scala without tears
Zahari Dichev, Bullet.io
June 12, 2019 · 10:16 a.m.
2232 views
Techniques for Teaching Scala
Noel Welsh, Inner Product and Underscore
June 12, 2019 · 10:17 a.m.
1296 views
Future-proofing Scala: the TASTY intermediate representation
Guillaume Martres, student at EPFL
June 12, 2019 · 10:18 a.m.
1157 views
Metals: rich code editing for Scala in VS Code, Vim, Emacs and beyond
Ólafur Páll Geirsson, Scala Center
June 12, 2019 · 11:15 a.m.
4695 views
Akka Streams to the Extreme
Heiko Seeberger, independent consultant
June 12, 2019 · 11:16 a.m.
1552 views
Scala First: Lessons from 3 student generations
Bjorn Regnell, Lund Univ., Sweden.
June 12, 2019 · 11:17 a.m.
577 views
Cellular Automata: How to become an artist with a few lines
Maciej Gorywoda, Wire, Berlin
June 12, 2019 · 11:18 a.m.
386 views
Why Netflix ❤'s Scala for Machine Learning
Jeremy Smith & Aish, Netflix
June 12, 2019 · 12:15 p.m.
5026 views
Massively Parallel Distributed Scala Compilation... And You!
Stu Hood, Twitter
June 12, 2019 · 12:16 p.m.
958 views
Polymorphism in Scala
Petra Bierleutgeb
June 12, 2019 · 12:17 p.m.
1113 views
sbt core concepts
Eugene Yokota, Scala Team at Lightbend
June 12, 2019 · 12:18 p.m.
1656 views
Double your performance: Scala's missing optimizing compiler
Li Haoyi, author Ammonite, Mill, FastParse, uPickle, and many more.
June 12, 2019 · 2:30 p.m.
837 views
Making Our Future Better
Viktor Klang, Lightbend
June 12, 2019 · 2:31 p.m.
1682 views
Testing in the postapocalyptic future
Daniel Westheide, INNOQ
June 12, 2019 · 2:32 p.m.
498 views
Context Buddy: the tool that knows your code better than you
Krzysztof Romanowski, sphere.it conference
June 12, 2019 · 2:33 p.m.
394 views
The Shape(less) of Type Class Derivation in Scala 3
Miles Sabin, Underscore Consulting
June 12, 2019 · 3:30 p.m.
2321 views
Refactor all the things!
Daniela Sfregola, organizer of the London Scala User Group meetup
June 12, 2019 · 3:31 p.m.
514 views
Integrating Developer Experiences - Build Server Protocol
Justin Kaeser, IntelliJ Scala
June 12, 2019 · 3:32 p.m.
551 views
Managing an Akka Cluster on Kubernetes
Markus Jura, MOIA
June 12, 2019 · 3:33 p.m.
735 views
Serverless Scala - Functions as SuperDuperMicroServices
Josh Suereth, Donna Malayeri & James Ward, Author of Scala In Depth; Google ; Google
June 12, 2019 · 4:45 p.m.
936 views
How are we going to migrate to Scala 3.0, aka Dotty?
Lukas Rytz, Lightbend
June 12, 2019 · 4:46 p.m.
709 views
Concurrent programming in 2019: Akka, Monix or ZIO?
Adam Warski, co-founders of SoftwareMill
June 12, 2019 · 4:47 p.m.
1974 views
ScalaJS and Typescript: an unlikely romance
Jeremy Hughes, Lightbend
June 12, 2019 · 4:48 p.m.
1377 views
Pure Functional Database Programming‚ without JDBC
Rob Norris
June 12, 2019 · 5:45 p.m.
6375 views
Why you need to be reviewing open source code
Gris Cuevas Zambrano & Holden Karau, Google Cloud;
June 12, 2019 · 5:46 p.m.
484 views
Develop seamless web services with Mu
Oli Makhasoeva, 47 Degrees
June 12, 2019 · 5:47 p.m.
785 views
Implementing the Scala 2.13 collections
Stefan Zeiger, Lightbend
June 12, 2019 · 5:48 p.m.
811 views
Introduction to day 2
June 13, 2019 · 9:10 a.m.
250 views
Sustaining open source digital infrastructure
Bogdan Vasilescu, Assistant Professor at Carnegie Mellon University's School of Computer Science, USA
June 13, 2019 · 9:16 a.m.
375 views
Building a Better Scala Community
Kelley Robinson, Developer Evangelist at Twilio
June 13, 2019 · 10:15 a.m.
245 views
Run Scala Faster with GraalVM on any Platform
Vojin Jovanovic, Oracle
June 13, 2019 · 10:16 a.m.
1342 views
ScalaClean - full program static analysis at scale
Rory Graves
June 13, 2019 · 10:17 a.m.
463 views
Flare & Lantern: Accelerators for Spark and Deep Learning
Tiark Rompf, Assistant Professor at Purdue University
June 13, 2019 · 10:18 a.m.
380 views
Metaprogramming in Dotty
Nicolas Stucki, Ph.D. student at LAMP
June 13, 2019 · 11:15 a.m.
1250 views
Fast, Simple Concurrency with Scala Native
Richard Whaling, data engineer based in Chicago
June 13, 2019 · 11:16 a.m.
624 views
Pick your number type with Spire
Denis Rosset, postdoctoral researcher at Perimeter Institute
June 13, 2019 · 11:17 a.m.
245 views
Scala.js and WebAssembly, a tale of the dangers of the sea
Sébastien Doeraene, Executive director of the Scala Center
June 13, 2019 · 11:18 a.m.
661 views
Performance tuning Twitter services with Graal and ML
Chris Thalinger, Twitter
June 13, 2019 · 12:15 p.m.
2003 views
Supporting the Scala Ecosystem: Stories from the Line
Justin Pihony, Lightbend
June 13, 2019 · 12:16 p.m.
163 views
Compiling to preserve our privacy
Manohar Jonnalagedda and Jakob Odersky, Inpher
June 13, 2019 · 12:17 p.m.
302 views
Building Scala with Bazel
Natan Silnitsky, wix.com
June 13, 2019 · 12:18 p.m.
565 views
245 views
Asynchronous streams in direct style with and without macros
Philipp Haller, KTH Royal Institute of Technology in Stockholm
June 13, 2019 · 3:45 p.m.
304 views
Interactive Computing with Jupyter and Almond
Sören Brunk, USU Software AG
June 13, 2019 · 3:46 p.m.
681 views
Scala best practices I wish someone'd told me about
Nicolas Rinaudo, CTO of Besedo
June 13, 2019 · 3:47 p.m.
2708 views
High performance Privacy By Design using Matryoshka & Spark
Wiem Zine El Abidine and Olivier Girardot, Scala Backend Developer at MOIA / co-founder of Lateral Thoughts
June 13, 2019 · 3:48 p.m.
754 views
Immutable Sequential Maps – Keeping order while hashed
Odd Möller
June 13, 2019 · 4:45 p.m.
277 views
All the fancy things flexible dependency management can do
Alexandre Archambault, engineer at the Scala Center
June 13, 2019 · 4:46 p.m.
389 views
ScalaWebTest - integration testing made easy
Dani Rey, Unic AG
June 13, 2019 · 4:47 p.m.
468 views
Mellite: An Integrated Development Environment for Sound
Hanns Holger Rutz, Institute of Electronic Music and Acoustics (IEM), Graz
June 13, 2019 · 4:48 p.m.
213 views
Closing panel
Panel
June 13, 2019 · 5:54 p.m.
400 views