Placeholder Image

字幕列表 影片播放

  • So that's my Twitter handle.

  • Add Matic Alina, please ask me questions.

  • Whatever.

  • I replied most of the time.

  • So I'm here today to talk about the No Dario, you might ask why Note?

  • Well, I am part of the notary s technical steering committee.

  • So whatever a lot of things.

  • No J yes.

  • If you have questions about North courting me, I'm so Ah, I'm also ah, principal accurate in here for me on a professional service company distributed around the globe, but busy in Ireland.

  • Whatever.

  • If you need us, we're there.

  • Check it out.

  • Check it out.

  • Also, another little bit of intro There is these lights.

  • If you have a laptop, there are some interactive visualizations.

  • So if you have a laptop out and you want to play with them these of these lights you can take a picture, whatever.

  • Whatever you want.

  • Um, so let's get started.

  • Um, when everybody starts with note, they start with a very simple question out of the bag.

  • A synchronous activity.

  • You know, you have a socket coming in on http request coming in and you want to react Thio those activity And you know what?

  • Everybody does well I can use the inspector protocol.

  • They expect a workroom inspector.

  • And they just left.

  • Yeah, more or less.

  • But what if we have 10?

  • Uncover?

  • Request our 100.

  • How can I?

  • The the bug on application running in production where I have a lot off concurrency in place.

  • Another I came from the Java word.

  • Whatever.

  • I've done this and this and I've said it.

  • You could stop a thread single tried in just the bag back.

  • You can't do that.

  • What?

  • So most of the stuff is because no Js is based on a concept called the evidence and you're probably are familiar with the No David Loop.

  • Um, okay, How many if you think they are from either with a no Devon loop.

  • Okay.

  • How many of you have seen this less people?

  • This is this the secret source?

  • Okay, that's the most Eden piece off node lower that you can find.

  • Took six months to write that guide.

  • Please read it.

  • If you want to know more about how note works and this is our no Devon loop works, probably not really easy to understand.

  • So let's reached one more easy to, uh, understand version because probably a little bit more clear to everybody.

  • So when JavaScript is exact executes, the only thing that note application does when it leads to a Iot, it talk to the colonel.

  • I think your barrier or a threat and says When this event happens, when this condition happens, please call back.

  • Call a function.

  • When this finishes that the only thing that that no does on dhe it specified a passing as a musket function.

  • And, you know, some event happens like you are receiving some data from a socket and that it calls back, and then he wants to call that function.

  • How does that happen?

  • That is E.

  • Let's see.

  • Whoa, there is an event you here and the event you means that all the functions are processed one at a time on.

  • So just to repeat at the dusky primetime specify effort at the function as a listener to some io event, and then the your event happens and the function is called.

  • But you know that is one cholera.

  • To all of this, we have only one function executing again given time.

  • And this is one of the key tenants off Annie Know Js and you know, Js function now you might ask why all of this matter why I'm doing a singles activity wouldn't make things simpler.

  • Yes, and now it makes things simpler to code.

  • However, that is one key piece that is a little bit obscure, which knowing which code is running relative to one another.

  • Um, also what about next week?

  • Promises and set immediate.

  • Now which one would learn first?

  • You scheduled a promise if you run a promise if you do next IQ, or if you do set immediate, you know I'm no throwing set time out Vero in there because that's even trickier.

  • So next week, every police executed before promises are resolved and before any other your events promises are.

  • If you do new promise, the function is executed.

  • Sink a lovely, but then resolve our synchronously and before any other io events set immediate.

  • Instead, exists eyes the full event loop that we told you that we've told you, you know, and have not thrown in city meets a time a Vera because that's another rival complication.

  • So again, the artist piece off information.

  • That thing that when a newbie starts working with note, is to know when a chunk of code is executed relative to one another.

  • So going back to the question out to the bug multiple a synchronous activity.

  • How do we do this?

  • Because, you know, we have multiple things happening.

  • How do we have a bad bug on that is happening Only when I'm calling three different routes at the same time and the moon is aligning and Marcie's over there?

  • I don't know.

  • It's really gets complicated.

  • And her I don't understand what what is happening in here is very hard.

  • So it goes back to a problem that something that you're missing in basket, which is the concept off their synchronous context.

  • So let's look at a bad, very basic, http Server of written in Notre.

  • Yes.

  • And you can see that we do our http, create server and we're passing a function this function.

  • In fact, when we receive an http request from a browser, you have a new logical sequence context that is being created, which means, you know, this is your transaction.

  • This is your htp requests and response.

  • This is a logical concept that is living in there.

  • Okay.

  • All the things that the sun from this one will be, you know, linked.

  • One wished another, mainly because they're part off the same closure.

  • You see, it's a closure created here, so they're part of the same closure.

  • And then when I create another closure, you know it's in here.

  • Okay, on dhe, the context is being the response is being propagated just by using that, um so it's really powerful, right?

  • However, there is no concept off our signals.

  • Contacts in the jobs keep language.

  • So you know it's something that is built in into our treasure works and how the event loop works.

  • But there is no way to control in any, uh, reflection oriented way this type of things.

  • So it's completely a logical counts construct, but is not a language, not the language feature.

  • There is some work in making these a reality where there's actually a concept in the language back and some of the war.

  • You can find some of the work done by the diagnostics working group in know Js.

  • Check it out and it goes a little bit into the deep depths of this, and it's really, really interesting to read.

  • Um, then well, if there's no concept off seniors context.

  • How can we track I?

  • You events?

  • So how can we know when things happen?

  • You know, there's a thing called Ace and cooks.

  • You've probably heard about a scene cooks in the past on dhe.

  • It's one of those, you know, new features off.

  • No Js that do that can do great things.

  • Also, you know, they're somewhat hard to use.

  • This is an example off Using them is actually really, really code.

  • Uh, can you understand what he does?

  • Wow, it's complex, and it also generates a lot of data, and I'm not going to explain it because it's a really that conversation.

  • So myself.

  • In my team, we have worked for six months trying to make sense about all this stuff and out to provide a way to reason about the synchronised context and their singles activity.

  • No, Joe.

  • Yes.

  • So you know.

  • And when you have this type of question, the best way to attack this problems, you know I am a software engineer, okay?

  • By trade, whatever s o.

  • You know, you go well.

  • You ask a designer Sorry, we can't do this.

  • So I ask.

  • We ask.

  • I ask a designer.

  • Can you please sit down?

  • We don't need a bit of a design.

  • Worship whatever to figure this out.

  • Turns out that they they answer to the question on out to visualize a synchronous activity is at bubbles.

  • So bubbles.

  • Yeah, that's it.

  • So let's make an example.

  • We have we have a nice, very tiny piece off asses off code here.

  • Okay?

  • Is the same server that we were talking about before you?

  • So we go to a lot of lights, so Hey, so we go to our So we're here and we have that code.

  • Now we can use this tool called Bubble Profit and this part of a sweet girl cleaning.

  • You might check it out late.

  • This is Quintin linked and out.

  • A cannon is a tool to relate some load.

  • So we're putting in 1000 requests.

  • Just spice things up to know what things behaving, production.

  • And basically, you're under your code lot.

  • Probably.

  • I've typed.

  • Yeah, we're on our code now.

  • You can see that out of Cantonese, cleaning things up a little bit and running a bit.

  • A bit of those requests.

  • Um, and it's basically now generating your visualization takes some time.

  • You know, this machine is not powerful little and these is a battle productive.

  • Now I'm zooming in on Dhe eso What we can see on the right side is the number off a synchronous operation being done off by this system.

  • And you can see that is doing you know, we have Ah, 12,000 synchronous resource being created by running after 1000 requesting know Js Does this help anybody?

  • Maybe yes, maybe.

  • No.

  • The important part.

  • Our boy for the down, we can start from the root.

  • So when the route this is the route note and represent the starting point of your application?

  • Yeah.

  • Then we can go deep and, you know, see the first part and the first part.

  • In fact, it's online.

  • 20 off our application.

  • Basic Dodger.

  • Yes, whatever it is.

  • And it's out called to serve a dot Listen, our server is starting to listen stuff.

  • Still, this is not helping me in the eye knowing what is happening in my nose application.

  • So the next part, it's this big block here, which is a bunch off on network activity, which is you can see it in green and this bunch of network activity.

  • It's that some bunch off anti frames, these air note core stuff, But then we have a bunch of another nautical stuff which come from how we receive a TCP connection in no jail.

  • Yes itself.

  • So you know that you are receiving a recipe connection on Ninja?

  • Yes.

  • When you receive an http request, you got that?

  • A TCP connection being open after this.

  • You, after this is actually the key part of our application, which is our set time out.

  • Now, you know, you see, that is a set time out happening here, and you see a fork and you can ask wise Is there a fork?

  • Now you can see two things.

  • First of all, the execution continue on the left because there's a big arrow that will give you a hint that execution left.

  • But our execution force, white folks.

  • Well, on the right, you can see that you know it.

  • Start a set time out.

  • Okay, on the right.

  • But then on on the left, it's when, uh, it's our promise dot then okay, which, if it's a resolution off the promise itself, So it is, um and there is a tiny bit of thing in the middle off note core bits and bobs where things are, you know, executed.

  • So you know, these things is clear enough, and we have a bunch of stuff the note cord does when it finishes on.

  • You know, it's for example, in here we're calling, ah, response dot End.

  • Which is where we send our response back to the user.

  • So we were talking this okay?

  • No, these understand is this is matches his matches my understanding.

  • Now let's spice things up a little bit.

  • Now, let's do a little quicker factoring in this system and, well, if you are following that is the full name of this thing generator.

  • Let's switch to the sink away when I think awake version this is functioning function functionally equivalent to the previous one.

  • No, that we're using dot Catch.

  • Always put a dot catch when you're doing this type of things because otherwise you will leak file descriptor and, you know, make popcorn off your servers.

  • So I don't do that.

  • Buddha catch your when you're calling promises.

  • So, um, you need you know, we're doing this.

  • So let's try.

  • Let's see if it's the same as before.

  • How many people think is the same?

  • I'm in Vegas.

  • He said they're different.

  • Somebody knows.

  • Somebody knows.

  • So these is This is Let me zoom in.

  • Okay.

  • So you can see that this is actually different from the previous one.

  • You generate a different diagram.

  • Why?

  • Well, first of all, we can know that we're actually using Maura Singles Resources.

  • Know that promises are singles resources, because their schedule it in there going to be a singles activity happening in the future.

  • So you see that you're scheduling 2000 more promises more or less than before.

  • Why is that?

  • And the reason comes in the way that I think await, I think, a way to specified and, you know, for every way that you do, Oh, you locate a bunch of promises that are not necessarily needed.

  • And they're going to be removed and, you know, fix in later region of this back.

  • I can send you some links if you are interested.

  • So they and you can see the difference here that, you know, we have our annual function, and then we have our sink away function, and it gets split in two and there is a bunch off anything in here which says I want friend with no file and this is you know, there's some throwaway called throwaway promises in it.

  • It gets you see some artifacts due to our promises, work and, you know, and this is a completing of the doorway.

  • Promises goes nowhere.

  • This promise is completely like generated, Just fulfilled.

  • Some speculate whatever.

  • Anyway, thes is with the sinker.

  • Wait, and you know that another step.

  • Interesting.

  • It's That's just you score, Becks.

  • You know why we're using this type of thing?

  • Why can't we just use corvex?

  • And let's do another example just calling a first rate five one of the perimeters off?

  • No Js.

  • So we go back here and we are running our files.

  • Example.

  • On dhe I came placing top, but it's not a really good idea.

  • So a lot of fights in there, So we're running it and generating some bunch of things.

  • And yet we g o um it's a magic sprinkling.

  • I don't know.

  • Here we go.

  • Now you can see there is another a slightly different ones.

  • This is fully lenient.

  • Lighten human.

  • Okay, you can see in this blob in this block, there's a lot of brown activity, which is a reading off files, a bunch of scheduling activity, which is the purple and then some green one, which is data.

  • So we have these blocks off brown activity here that you can see and you know, the first last week on the 1st 1 And the 1st 1 is our F one function, and you can see Oh, maybe we're reading a file.

  • So this is scheduling our read of the fire.

  • Then we have this next block afterwards, which is in fact, a combination off.

  • Three different a synchronous activities because no, yes, in order to read that file is actually accessing the file system three times.

  • And it's completely in it for you to just call a fast refile.

  • But it's segmented, and it makes things interleague so that you can use multiple signals activity at the same time and is doing treat and they doing three things and he's calling dysfunction read file after open, which is totally a note coursing, and we're not should not really worry too much about, and now we have the first we have the first file and then the second file and then the third file.

  • Okay, this seems I can understand this.

  • So let's reach, too, I think a wait.

  • Okay, now you should have learned we should have seen that.

  • It changes significantly the structure off my application.

  • And it's, um it's actually very It's actually useful because it moved from something that is very hard to read and very after maintained, or something that is way better to read and maintain.

  • So I like it right.

  • I'm a fine, by the way on dhe.

  • So what is happening?

  • It's now you can see that the actual bubble pop art, as we call it it is likely different than them before because you can see that there is way more scheduling activity happening and you can see where the true way promises are.

  • So there's a truly promise here vehicle really actually calling a sink away to three times its away three times.

  • So we have three throwaway promises, and we have one here, one here and one here.

  • Now that is on.

  • We can now understand how things are getting into lived between each other on how we can use this information to write better code and maybe fix problems.

  • One more thing.

  • It's We have written our our code in this way.

  • Now we can also very quickly revive that code.

  • Toby in parallel.

  • I know that changing a bunch off cold back hell functions to be parallel.

  • It's hard doing it with the sink away.

  • It is a matter of training.

  • Three lunches, coat.

  • So benefits there know that I'm not using a wait and let's see how it goes.

  • Take some time.

  • Here we go.

  • Them Stillman.

  • And now Now you can see that in fact, the three throwaway promises that we were talking before have gonna have disappeared.

  • And we now have our only three blocks off reading our files.

  • And we can impact this rap.

  • And you can see that you know, there is all that.

  • The things were gets generated properly and stuff like that.

  • And that is a lot off information that you can that you can gather from the stool and to visualize your A singles activity it understand out your your note process work.

  • In fact, it on some analyses on some some open source modules.

  • These is from ah ah library called.

  • I profess Andi.

  • It's a distributed web platform, and we've done some optimization sze in there and there was some some there was things that could be improved.

  • And you can see that is a lot of activity in here.

  • A lot of things that are, you know, chained together and so on and so forth on dhe, you can read all of this in this issue.

  • If you're interested, it's ah long.

  • It's a long, long, long paper off explanation on what was the problem.

  • We fix it in the end, we fix it.

  • We got the 30% performance improvement.

  • So it was nice.

  • It was It was It was a nice one.

  • Okay, um, so let's go a little bit into some performance consideration, or now you write your note application and how to improve them.

  • So, you know, we've talked a little bit about the M and loop, and now the fact that you're a Iot, Rance, one at a time, right?

  • And we schedule functions.

  • So when we receive a request on dhe Israelis, we scheduled some activity to happen in the future.

  • We set a function into our Evan Lucas machinery, right, And they would call me back when it's finished.

  • So when this is lower your operation, that function will stay alive longer.

  • Okay?

  • Which means that they can accept more stuff from I can accept more requests before returning.

  • Right?

  • That's what everybody will do.

  • Well, I have capacity.

  • I'm not doing anything.

  • I'm hydro.

  • So I get more data from you know what's up, Mauricio request.

  • So, yeah, it's increased the amount of concurrent tasks because I have more soup you band with.

  • Now I'm waiting for stuff to weapons so I can execute stuff did.

  • However, the morning increased the concurrency and the more increase the memory consumption.

  • Why?

  • Well, we have for each one that we received, we are locating new closures.

  • So new closure gets allocated new objects and all of these occupy memory, which is, you know, precious in most systems.

  • Um, the moment you increased memory consumption, you increase.

  • You make the work off the nice garbage collector harder.

  • Why?

  • Well, because you know, he has more stuff to clean up, and you will each his work is even The performance of the garbage collector is getting better and better and better and better and better and better and better every year wear scheduling more stuff every year to every moment to do more of us.

  • So it increased the pressure on the garbage collector too, to do work.

  • And these it again, which collector?

  • Where does it run?

  • Is it magic?

  • No, it's not magic.

  • It runs on a CPU.

  • And you know, when you were working on a container system or are deploying know Js in production, you are doing you put Probably have one or two or three, maybe.

  • Course I don't know.

  • You tell you most of the time once one core.

  • So if rogue average collected running, maybe my no process cannot run.

  • So we have a problem there.

  • Okay, there's contention.

  • So in the end, until this means that the garbage collector would steal my CPU cycles perfect on will steal my CPU cycle from the JavaScript critical path, which is, um, which is a little bit of a tricky thing.

  • So, um, the net result is that late in an O.

  • J s application, leighton see and throughput are tightly connected.

  • So the moment you see an increasing leighton, see, you will see also likely a decrease in trouble, mainly because they're linked together, by the way the note works and the fact that typically it can take a huge amount of Fei concurrency compared to other platforms on D's is one of the things that you know having doing get us a job to go through and putting no Jess application in production.

  • It's one of the most misunderstood concepts.

  • About about Nigel.

  • Yes.

  • And think thinking that this two counts of latent and through good are not connected to each other.

  • And you, you should always remember.

  • This s so that this tool is part of the clinic day.

  • Sweet.

  • You can find it there.

  • There is also a beautiful speaking whatever.

  • Um, so if you need some out in improving the performance off your node.js application, reach out a say hi on Yep, That's it.

  • And again, this lights, you probably want to check them out.

  • I don't know.

  • Hopefully.

  • Hopefully, yes.

  • You know, I will take about them sooner rather than later.

  • Somebody's taking pictures.

  • Thank you.

  • I put it right there.

  • Put it there for you.

  • Um, So, uh, yes.

So that's my Twitter handle.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

泡泡你的Node.JS I/O - Matteo Collina | JSConf Hawaii 2019 (Bubble Up Your Node.JS I/O - Matteo Collina | JSConf Hawaii 2019)

  • 1 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字