Is TypeScript (NodeJS) Faster than Go?? | A server comparison

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so if you've been on twitter at any point you would think that javascript is the greatest language ever and that everybody uses it everybody except for this guy thank you andy wonk why though beccan has proven to be good with javascript well searchy i don't know if i believe you let's find out okay because as far as i can tell every javascript library claims that it's blazingly fast blazingly fast testing blazingly fast spreadsheets blazing fast web sockets but is it though is it actually blazing fast or even fast well the only reasonable way to do this is to use another popular backhand language say go that has similar characteristics garbage collection and let's just see which one's faster blazingly faster what about rust i thought you loved rust i do maybe not as much for the back end though it's kind of uh not fun all right so let's go over the experiment there are several web sockets that will all be connected to a singular server the sockets will inherit the event emitter interface and with that a function called push sockets will emit out a single message and can be pushed a single message with go i use channels every message that the server gets it will then emit out what is listening is a chat program if a user sends a message bang join in a room name it will be added to that room this experiment involved 20 rooms that would be distributed among the spawned sockets it produced the same order every single time the messages sent will be an object that contains some information that should be json parsed manipulated and by manipulated i mean i just add one to a property which is always 68. nice and yes the test client is written in rust the message then will be stringified and handed back to each client the interface on the way back is of course going to be an array of messages that will go to each client one at a time now i've written the program so that they are effectively identical since there are no channels in node i just simply used event emitters and then just a function to push it back through now would it have been more efficient for me to have the same function in go that i can just push one message through it could have been but i felt like it was kind of moot for this server but each server will stringify the message and then divvy it up among the sockets as opposed to json stringifying per socket so i really did try to make this as fair as possible and of course you can go check out the code chat again from twitch decided on the name which i did vote for sock it to me baby instead you guys chose tyrone biggins dave chappelle's lovely character this is a five o'clock free crack giveaway you degenerates either way links in the description you can go check out the code validate that i didn't you know make anything unfair so let's briefly go over the test client because i want to make sure that you understand the experiment that way the numbers make more sense effectively every 100 milliseconds i will emit a batch of messages the batch of messages will be in the following format it'll have a timestamp which is the current one we grabbed a small stringified string message and of course that number in which we increment by one on the server nice that way every socket has a small amount of time it's actually sending messages in a large amount of time it's actually waiting to receive messages this also allows for a very even pace of messages coming through that is because i always make sure that i'm sleeping only a hundred milliseconds max between each set of messages being sent and if at any point i have exceeded the amount of time it takes for me to send those messages versus my sleep cycle i will let myself know and guess what it never happened once so we're good to go then of course each socket will wait for its message that it's sent to come back to itself and then measure the difference in time and print it out in a nice csv friendly format in which i can use python or google sheets to do a little bit of analysis using of course python we can do a basic breakdown of the statistics you'll see that this is a 500 connections made to the server for both typescript and go the top numbers of course are typescript the bottom numbers are go you'll see that the mean is significantly different and in favor of go i did not run any man whitney test to tell you if this is actually technically different but a simple looking at the numbers should make it fairly obvious even in the 75th percentile that there is a large difference between the two this 20 millisecond response time difference doing the exact same thing except a thousand clients on typescript and a thousand clients on go you'll see that the mean is vastly different the mean did shift upwards by 10 milliseconds on go about 10x on typescript the standard deviation is huge the mean is about two seconds required response time versus goes 66 milliseconds that means the median message wait period on a typescript server was 1.65 seconds versus on go 67 milliseconds now remember this was the same server in lenode i didn't even have two different servers running i would actually take one up run the test take it down take the next one up run the test is a huge difference and it only gets significantly worse but i feel like looking at this data doesn't quite do it justice let's look at it with some graphs so i took all the timings from each one of the servers and i actually reduced down the set taking like the first hundred averaging and taking the second hundred averaging it so i could just look at a smaller set and plus it causes the noise to be just less right it just is a little bit smoother of a graph so here's that exact same data that we are looking at with only 500 connections except using google sheets you can just see with your eyeballs that the red line being go is significantly lower than the blue line being typescript the y-axis represents microseconds taken and of course the x-axis is just simply the samples in other words they represent an average over say a hundred messages each data point so here's the thousand connections and as you can see it's just like it's a blowout go is just flatlined at the bottom whereas typescript goes way up to the tippity top almost six seconds at one point to dive all the way back down and back up so variability just huge and it gets even worse above a thousand all right so here is 1500 clients connected to that same server at this point you can see it is just a disaster this means that typescript is going to die i had troubles running the server longer than about three minutes because it kept exploding whereas go just purred along a slight increase in round trip time but you know nothing much to bat an eye at and look at how efficient it is typescript at this point was also consuming about double its memory and it was growing quickly and of course every time we added more clients the typescript line just got steeper and it would live less long go just didn't really change that much so you're probably saying well prime you probably were on like some multi-core server that really just disadvantaged typescript and made it so that go because it can be used on multiple cores just it gave it such a significant advantage false it was on leno's smallest instance which is a single core one gigabyte of ram five dollars a month [Music] so that means there was no advantage if anything it meant there's probably a slight disadvantage for go not being able to spread all of its green threads across multiple cores instead having all of those different go funks running on a single core yet it just crushed so you're probably asking me is it actually better to write go though i would personally say that go is actually a nicer experience than typescript one big reason is that go controls and runs its own tools there's an expected format of code which some of the formats i dislike some i like but i'm okay with that all projects universally look the same second they have their own tools their own build system their own way they get modules there's not yarn versus npm versus this that and the other and it can be executed effectively on any platform so it has a lot of the similarities as node just what i would consider a better ecosystem the code itself i feel is better channels are definitely superior to anything that javascript has now go's also increasingly growing with the preferred choice a lot of that's because it's really fast not as fast as rust but it is really easy to write like typescript easy to write so you kind of really get the best of all worlds when using go now another critique you could say is that my server was too simple that i was spending most of my time just making sys calls sending messages out across the wire and you're absolutely right i do think it was too simple that is why this video is a part one okay we're gonna do multiple parts to this you know what i didn't use in javascript i did not use async await i didn't want to disadvantage it at all hopefully you're pretty excited about this i love comparing languages and seeing similar features and ultimately i think go is an incredible choice i think it's too often that people just reach for typescript because it's easy it's what they're familiar with but if you just take a little bit of time i would even venture to say that go is simpler and quicker to learn than typescript and if you take that small amount of time you can write efficient servers that are really easy to scale with a team even a team that's dominantly comprised of juniors so if you like this kind of format if you want to see more of this okay hey i'd just like to let you know that you you can make some very beautiful uis uh you know hey you know compliment to you okay but you're a disaster on the server so get up and get the hell out of here man you're walking slow oh that's your speed okay standard speed yeah trust me i can see it i can see it from here tell me what you think i should test and compare i personally think we should probably throw in a database and use a little async handling with rxjs and just see the difference let me know if you think typescript will actually perform better once the server gets more complicated or do you think go is just going to win of course all this is built live on twitch and discussed in the degen army's discord okay so i hope you look forward to part two and please say something down below tell me you're excited tell me you want to see cause if you don't tell me i don't know i stop doing things because people are just like so if you don't hit the like button or you don't say something down below if you don't give me the signals back i assume you don't want to watch this so talk to me tell me you like me tell me you want my body [Music] [Applause] is this five o'clock free crack giveaway
Info
Channel: ThePrimeagen
Views: 214,888
Rating: undefined out of 5
Keywords: software, vim, programming, javascript, typescript, software engineering, web developing, web developer, software developer, developer, cpp, programmer humor, humor, reactjs, js, ecmascript, tc39, Netflix, Engineering, Engineer, Facebook, Amazon, Interviews, Software Interviews, vimrc, neovim, spacevim, vim c++, vim editor, text editor, vscode, vscode vim, vim plugins, autocomplete, vim autocomplete, nodejs, twitch, developer productivity, spacemacs, algorithms, datastructures, Data Structures, python, bash
Id: h7UEwBaGoVo
Channel Id: undefined
Length: 9min 54sec (594 seconds)
Published: Mon Jan 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.