 Good good Good, how's your brain so far like you know like first day like functional programming like distributed computing concurrency I think I think my brain already exploded like two three times and then just preparing for this talk already exploded two three times So but I think it should be okay compared to you know all these like other stuff okay, and So my name is Makoto. I'm a web developer a company called new bamboo based in UK So I'm I'm like rails developer like probably most of you guys and but at the same time for last one year and a half I spent Yeah, yeah and I have translated and be called the D. Ruby book Which original original book is this one and so translated and now from Prague parts and Yeah, and also yeah, some people wrote like a A nice book review and actually the title rails previous talk Davey did like a D. Reverse event machine by Eva Churchary Ravi MQ This and then she said it's a bit misleading But I was even more misleading because even though we say there is a follower. This is the only time the world rails comes and We didn't even say this one like you know, we are kind of shy It's actually all you have to blame to Matt's because in the forward of this book He said like, you know, where is his a follower? They just follow D Ruby. So yeah, just way much And so here there's Masato Seki I call sexy some and he's known for Ruby committer and also so the also D Ruby Which is a talk main Tokyo? Talk topic about this talk and also probably less known, but there's a one called Linda, which is a this week I So Linda is a Distributed top of space Which is awesome, but we don't go through detail today and also more a proper people More people knows about actually the ERB and he actually is actually also be LB and also the less even lesser known fact is he's a Pokemon master and he had a 2010 tochigi prefecture local champion and then he's not even a senior league We're senior league in Pokemon is means like a 15 to 18. So he's in a master league champion be afraid and Kite kudasai so Okay, so During days of he works at Company who makes a medical system and he's actually a Ruby developer and this is one of the example of what he His software is and it's like highly embedded and also he had the center with real-time Patient information and it's all lots of network Programming involved and also lots of the GUI programming is involved so when I talked to Yeah, I talked about the kind of latest hotness about like in a node. Yes eventy and then when I talk that to sex And he said well, I've been doing that for 20 years using C so that's how he's master and also he's kind of big deal in Japan and So that because he's been talking about he's a regular speaker in the Ruby car. He's since 2006 That's like 2006 is when Ruby car started. So he's I think Except Matt's probably one of a few people who just keeps talking about the Ruby and the ERB for the last four or five years and Yeah, so this is kind of history of sex and and so the blue is a kind of I call BD before the Ruby and the orange is a kind of after D would be so AD and the book was published in 2005 I took about five six years to get translated because there's no one else to translate until I came in 2010 but because that time like he had a lots of things to talk about so we did a lots of Brainstorming and to have to introduce a new concept. So it's actually very very new books and Actually, I think yeah, there's a yeah Okay, and so before we start we'd like to thank you to Ruby no Kai and also new bamboo for both Sponsoring our fly and accommodation. So thank you to Okay, so today we're gonna talk about three things. What is D Ruby? So who's ever used D Ruby before Okay, 30 40% who's in the last session of David session, okay? And so who's has used D Ruby before but switch to event machine or cello? Okay, there's no one. Oh, okay. So who has the original D Ruby Japanese book. Oh Wow, it's very popular and Do you have English book as well? Good. Oh, yeah, you review. Yeah, so yeah, because there's a lots of content So, you know, you should buy and oh, yeah, there's a 40% off coupon is Ruby come 2012 So, you know now is a chance limited chance to buy the book. Okay. Anyway, so first of all We're gonna even though like some people might already know D Ruby. I I'll explain what What D Ruby is all about and after that I'll pass the mic to sex and so like he will talk about kind of background of like The ways to go to start designing about D Ruby Then he's going to talk about the all the designing concept and this is where he's going to introduce some of the metal programming concept And after if we have a time left would be a Q&A Yeah, okay, so now fix them No, that's me. Sorry So why is D Ruby this D Ruby stands for Distributed object system and so what that means is when there are multiple processes one process can invoke method in different processes and it's not only that you can actually Get the remote object and then you can pass the remote object as a like argument of to send Invoke method or you can return the remote object as a return value and More importantly, it's like 100% between Ruby so there's no seed extension or anything and Also, it's part of the Ruby standard library. So probably like 100% of you if you are a Ruby developer and you have Ruby installed you actually do have the Ruby So today we will talk go through some of the source code and if you you are interested please feel free to open the you know source code and they're just examined by yourself and This is a demo so there's a Two IRB sessions I'll go top one as a terminal one and the bottom one as a terminal two and I don't know how to stop this video. Oh Okay, I cannot stop this video. So It says like it Pass it to argument one is a URI and the second is the object you want to expose to the D Ruby and in this case 5d will be and you expose hash sent is if you do DRB front you see the hash and if you go to the bottom one It's called Terminal two you also rate star as a star service, but you don't at this moment you don't put your own URI and When you want to connect to terminal one you do a DRB object new with URI and you pass the URI I over the terminal one and you can see that KBS valuable actually has a hash Which is exposed through terminal one and if you put the greeting hello wall you can actually see from You know even though you put in terminal two you can put in you can see in terminal one So this is a very very basic of the Ruby and then demo two So then what happens if from terminal two? Let's send like standard output of the terminal two They it kind of sends IO object. Hmm What interesting then let's go see terminal one Yeah, and if you see yeah, you can actually oh, okay, you can send IO object But you actually if you see very carefully like if you see DRB class method It's actually replaced by the one called DRB object. So it's kind of reference object It's not it really didn't pass the IO object of terminal two So when from terminal one if you do pets It's actually referencing back to the terminal two and they kind of grabbing the stand up out of the terminal two and they're doing Hello again Okay Yeah, the takeaway from this one is so I keep saying like you know This is server and the client but this example actually shows up both servers a one point wine server Time your wine server, but at the same time terminal two is server. Okay, that's very Important Okay, and the third one is a distributed queue It sounds like you know complex but all you do is like in Ruby There's a classical queue which is is a bit like array which has like a push and pop method. So if you put the queue object into the the the hash and the Second yeah, so moving and if you take the queue on terminal two And and if you try to push the value to the queue From terminal two You can you should be able to pop it from time now one that almost looks like a ray But however, what happened if you try to pop from time now one when there's nothing in a queue Then he actually waits until something gets put So let's see at the time now to if you do push to or zero That's the moment we it kind of releases and the shows the result. So let's try it again it holds it waits then it pushes so One thing important is even the distributed process What you mean is like you have multiple processes and they're talking to each other as a server of each process actually doing the math threading and Interesting thing is if it is a single mono thread if you do the pop in terminal One and the waiting you shouldn't be able to receive the push from time now to because there's two to going on But because of my threading It works. Is this my explanation? Good I will approve them from another master And Then it for the practical example Dave you already talked in the previous session, but also another example is he Is he there? Okay. Yeah, he's mocking and he works at a company called kukuba in Japan. It's one of the biggest recipe sharing site and they had a huge court base and To run the aspect it takes ages. So what they do is like it They use the ruby and the binda which is a distributed topple space to scale the old aspect Is it what you do? Okay, so it's good. So yeah, and there's us if you go to slide deck There's a slide of his talk. He did a supple ruby kaigi, but Muraken is right there taking photo of us so you can feel free to ask him Okay, and another example is actually David already explained that like, you know kind of starting point and prototyping So you start from the ruby because the ruby is pretty much everything to expose the things So you can put like any day structure you can put like array or cue or Set or like tree or I'll be tree or any like you can use as a graph day base or a document They base or key value store pretty much anything and then once you figure out this is exactly the domain problem You won't then you can move on to a right solution just like David did for the moving to Even though some of the things I could say you can use it with binda Anyway, and also this is also he did a blanket. He's a former city of the Twitter He also came went to the same way. He eventually released his own message in q-core styling But before the he I had he used the ubi so I kind of stalked him and said are you sure you really use the ubi? And this is a response says it. Yeah, I actually used it. Okay, so that's what the ruby is and now next I'll handle what to Master section and that is actually me That's my drawing by the way Hi Makoto program to me using this script I Read it I've been professionally programming For almost 20 years At first I was used to all-star links programming the examples of IPC. Ah, sorry It's a style to connect small processes by IPC Interface communication The examples of IPC are folk and pipe and also a unique system system 5 Had an API for message queues shared memories and semaphore then I met the web in the mid 90s and run CGI programming At that time it was common practice to use CGI for web programming It was fun to bring the simplicity of HTTP into network programming I reload some of network programming in CGI. I was surprised that I Was able to use a higher-level language like park, which is not surprising anymore BD1 Then I met Ruby That was end of 90s I met Ruby and web server written in Ruby It's cause HTTP server written by Shinjiro Hara Hara server is a lot older than webrick. It was a very small server and easy to tweak I used to put Ilwe server on it. I was initially extending Features on the web server, but that's eventually changed Instead I started embedding in the web server in applications This was similar to IPC-style programming Where each application had an HTTP endpoint There's also another change to my programming style I started writing everything in Ruby With Hara server as a term using various language and connecting them by a CGI Then I realized that my programming style is not so cool anymore This is because I Had to translate Ruby's classes and methods into the web for example HTTP restricts the way you exchange objects The server client model Restricts you to one way communication. I cannot get remote objects Call each other like with Ruby objects in the same process You also spent time trying to come up with cool URLs but that's Not the core of your application. I'm not happy with this approach It's not so liberating to communicate via the web even when the same Ruby processes Talking to each other Isn't using web to generalize to when Ruby processes went to talk to each other This was about that time I was getting used to programming in Ruby So I wanted to solve this frustration by myself. I Wanted to write a very linear centric solution. I decided to write distributed objects That acts like Ruby. I Don't want to declare interfaces nor specify declarations in arguments nor in written values Method of implication in Ruby looks like message parsing rather than function calls Maybe I can override the message parsing mechanism and extend Ruby with our application noticing it What we need is a proxy object that acts exactly to be exact like Ruby and the server That has the proxy The gist of this system, which is D-Ruby is to create fake Ruby objects Next I will introduce some of the techniques I use to implement D-Ruby The first ingredient is method mission Method mission is invoked if an object receives unknown method calls You can use method mission to hook in when someone calls remote objects via proxy Let's see how it works This is the first implementation of D-Ruby from back in 1999 D-Ruby object is a proxy object Method mission catches a message and its arguments Then transfers them to the remote object to evaluate Next is Marshal Marshal is a library to serialize Ruby objects This example shows that D-Ruby protocol object dumps arguments and returns values using dump method However, that is a problem. There is a problem with this approach Ruby cannot share files nor thread objects. So it raises exceptions Let me explain how D-Ruby solved this problem If Ruby cannot share an object, it converts the object into a proxy object Then share the proxy instead of sending the object itself D-Ruby sends the reference of the object You want to send This is how you implement the logic When Marshal dump fails Then D-Ruby calls the object with DRB object new Then dumps it again Isn't it cool? Next is ID to RIF and send I will talk about the server implementation A client process marshals the object ID, message and its arguments to the server Once the server receives this data, it has to transfer to appropriate objects To do so, you need a way to look up objects and transfer these methods This is where ID to RIF comes in ID to RIF converts reference IDs into their app associated objects I guess you rarely use this method Then the send method sends out message to an object Once the object is found, then the RIF server sends a message requested from a client to the object I also need a few other techniques to make D-Ruby behave Ruby, I behave like Ruby What would you explain? So, so far easy, right? Yeah, you guys kept up to speed. Yeah, I hope you guys can keep it up for the next one as well because I really struggled last night. I This slide we just added last night and then I spent three hours trying to understand what this really means In the end, I was half crying like, I don't understand. He just kept trying to explain to me So I'll try my best and if it doesn't make sense There's a Eric or in the there's also Matt who can help me explaining. So Yeah, there's a one called, so there's three things How do you recover unknown objects and the second is multi-threading a bit more detail and the third thing is Handling method code with block. So what do you mean by unknown objects? Let me demo again So the same terminal top is one bottom is two in bottom two You just define a class called foo which has a method called bar So if you do foo.bar, it just says bar. That's easy But so what if you try to send this object to terminal one, which doesn't know anything about foo class Is it even possible? So let's see that do KBS foo and it has foo object and in the top It's gonna happen and it says now it says it's not called DRB unknown object And then if you look at it, but you still have the name called foo and it has a string in the buffer if you Excuse the method called bar. It says undefined method because it's like your unknown object It's not bar. Okay. So what if I redefine and define a foo class on terminal one and do it again Still it doesn't understand but it really has a method called reload Which kind of reload it and then we generate the foo object So now if you put that reloaded one into the object, you can see the bar Easy, right? I think So what has just happened? So who did it replace foo with DRB unknown? Okay, let me try to explain so Yeah, so when in terminal two try to Put the object into the hash eat that do martial dump, right? You learn that right then Whenever you put it the hash is owned by terminal one. So in this situation terminal one is a server so When time you have to dump set terminal one lose it and because it doesn't the foo doesn't exist He raises error called name in an argument that time It's kind of similar to you know the you know reference one when you try to Martial it you can't martial it. So you replace with the Reference object kind of similar thing here. It does it generates DRB unknown object and what this one does is he just checks the error string and It doesn't bring you expression because there's no there isn't I think way to actually say what's the name and method So it just passes the error message and they put into the name and they put the same thing in a buffer Okay, I think this is still okay, but why if so now terminal one server Doesn't have foo object, but it does have DBR unknown object. So if you terminal two try to call that object again What happens because that object is not in terminal two. It's in terminal one. It's how does terminal one returns this unknown object the answer is It's simple. It just returns about the buffer. So every time it just returns back to the serialized object So in terminal two when you lose it It just generates a few object again Okay Silent yeah Can you notice if you understand? Yeah. Yeah, all right. Yeah, okay, and so then next so when you do the Yeah, they find the foo object in terminal one. I did a magic magical method called reload. So what's inside? It's just actually martial load. It's the same pattern We use like you know, you try to load if it does it does exist It works if it doesn't rescue it and create the new DBR unknown jet So if you actually see Try to see the you know in a terminal one demo example if you try to inspect every time you see the DBR unknown jet But it actually generates new ID I tried to clarify one thing, but he wasn't paying attention Okay So the second is multi-threading Initially, so he he brought the pattern of the multi-threading in socket programming from the Hara-san sub Shinichiro Hara server What he does is so when you D-Ruby acts as a server if there's any incoming request You hold it one But if you get other requests at the same time if it's single thread Like unless it's like event loop or anything it kind of holds if you're processing something. So it spawns a new generate a new thread and This is very important especially this example. So Imagine this is in terminal 2 you are in a KBS Which is a hash and if you do KBS dot each and the you pass a block What's it's actually happening is when you do KBS dot each the KBS hash is in terminal one So you are actually invoking the method of each in terminal one But as soon as you try to evaluate block that wasn't dumpable. So he has a reference So it goes back to terminal 2 and then it gets evaluated to the place where you you ask the request so Let me explain another example if you that KBS is a like large Yeah, big hash or something and if you do the each so every time you do the each it goes To the terminal one then it goes back Evaluate then it goes and it goes back and evaluate then if it's again single thread This this communication causes a deadlock, but because you're using amount of threading that doesn't happen That's how it would be is utilizing multi-threading Yeah, and so that this is how he actually works. I think you already seen the similar Lion called in the method missing part like it's doing the object of send But in this case you are calling block.co inside the block easy, right This should work right Does this work? Yeah, raise hand It's actually wrong If you do this it actually raise It works, but if you do the break inside each block it actually raises local jump here Do this make sense? Yeah, because I really struggle to explain this one. Let me try my best So inside you know the control flow like next or Break if that is called it goes outside Yeah, it breaks from the current block and it's trying to go back to the environment you are in That usually works if you just do a method invocation voice block in normal thing But what it's happening is you know every time you are in the each and coming back you have been In a new thread which is a complete new environment So the environment where you did it is lost hence. There's nowhere to do the local jump. That's why it raises Oh, you know the wow amazing takes three hours for me to understand what you did it in was two minutes impressive Yeah, actually, can I grab hands for him? Yeah So the work around is once you understand it's quite easy all you do is that you catch it and then you break by yourself Once you understand I think yeah, did you get it? You know, that's Get it I think so I'm very happy so now I'll pass it back to section. I'm loading map of script It's been summarized But we have explained so far First I talked about the history of my programming patterns and how they are we was born Then I took you through various metaprogramming techniques behind daily You make you make things programming is cool. I'm gonna make metaprogramming is cool But I feel like some people are using a metaprogramming as an end in itself as adults that too I Use metaprogramming for deal. We are dumb nasty But right had not to reveal it to the end users however If you look carefully metaprogramming is everywhere you may not even notice that there is magic But that's the most magical thing about it. I have explained everything You need to implement DLB. It's your turn now Now you can write your own DLB a cool one, please Thank you. I forgot to say one thing about why you even need DRB undumped Do you know why? Anyone so like something like a render like distributed tuple space When you try to do from one client another trying to exchange object If because it D ruby relies on martial dump and law for everything so if By the time Rinder tried to lose that martial dump It rate it raises unless you have every single object clients gonna ever pass Passing future. This is a kind of ways to walk around us. So it works So distribute it's distributed but you can use it as like a central repository to pass object I think that was very important things I wanted to explain and now questions Okay There are some objects that can't be marshaled right like a prop can't be marshaled. Yeah That's the Ruby have a way of managing those types of objects that can't be marshaled. Okay question was so Ruby cannot Martial dump some of the object and how it works. That's a demo to example. So like I stand I owe You can't dump so what it's doing is like it dumps raises Exception catches it and it just creates a new object which has a reference information of the IO object Passed to the server. So when server this server tried to execute it. It doesn't skew in Server but it just goes back to the client client excuse. So one of the first mistake Yeah, proxy. Yeah, pass of the First mistake I gave was I thought yeah, I can pass proc so I can use distribute the processing Into different processes. So I created a lot of proc and I send it and I The I asked the remote ones to you know evaluate to use the CPU power and it goes back Well, I was actually doing like a proxy back and actually client was processing everything Once you understand it's like kind of silly, but yeah, you can Test it perfect example If you try to do I owe and if you try to the IO read a file read or something that you can see where And you know you have a time in a different directory that you know exactly where it's executed That's a way good easy way to debug how the database behavior that and that's kind of way I learned That it's called pass by reference Compared to pass by value. Yeah Next question Yes two questions first Does DRB support multiple topologies as opposed to single point-to-point? it'd be like broadcast topology or maybe ring topology and Also So first question is what kind of distribution topology do we support and the second one is what kind of security model it provides? No Okay, so Fundamental principle is like some of the distributed product tried to be to solve the problem of distributed things His his main motivation is he wants it to create the object which just behaves like maybe doesn't really have a broadcasting No, so that's why he didn't implement Maybe you can implement on top of it. I think Yeah, Rinder chapter I think six seven. Yeah, seven of our DVB book. There's a fantastic Library called Rinder you should definitely have a look 40% off now Security model I say no because Ruby doesn't have it but I Think you can use There's a way to use SSH over and that's the chapter 13 of the DVB book Sorry, I'm making up the chapter number because I don't remember but that's enough. I think second last chapter. There's a one Actually, I was translating but I didn't really have Understand, so I hope you understand my translation And also Yeah Okay So he uses SSH solution, so he's gonna explain now Now He just copied exactly the same way found in a DVB book There's a way to use as a gateway using SSH, so I think you must buy one Thank you Yes, are you asking question? Oh statement. Yeah There's if you there's also a you can require DRB slash SSL and I'm not sure if there's much documentation on that but there are References to it either on Google or on the Ruby talk mailing list archives from several years ago So you should be able to find information about both SSH and SSL both in the book and Old examples. Thank you, Rick. Any other question? Yes, again Do you know any projects where DRD Ruby is used right now? I remember that there was a time where our spec used it I think it still uses it as far as I remember every time I'm aspect If there's a once more warning says like DRB is not enabled, but I think if you do yeah, and the spoke also uses it Yeah, and I think God, you know the monitoring one. Yeah, I think he uses it. I think yeah I use pride and then like every time I talk about the Ruby day people said so, what do you use it for and I just realized I'm using every day I'm very pleased Yes Discovery Discovery so question was how do you do discovery service the short answer is The if you want to do it very simple way hash it's actually discovery service. So one of the example is like you Name service or what you want to find out? So if you have multiple Ruby nodes out there on any examples, you're connecting to this. Yeah, so you're connecting to the URL directly Yeah, you already know ahead of time. Yeah, is there a way to discover your other in the Ring finger and you made one as well Yeah, you wrap say okay, so yeah, so yeah, there's a there's a one called ring finger and Also, I think every kind of wrapper because it's harder to use Makes it more convenient to use yeah, so That's the one yes Anything else good. Thank you