 Hey everybody, it's Brian. I am back. So everybody say welcome back Brian If you don't know I was on vacation for two and a half weeks and I went through I'm from America But I went to like Barcelona. I spent a week in Paris. That was actually amazing What you know, we took a cruise down through this whole little area went to like Naples and Rome and Monaco Cairns nice few other places. It was it was amazing It was hard to believe that you know just a little bit over yonder's where all the turmoil in the world's really going on right now Maybe that was a very ignorant thing of me to say, but you know what? I mean, it seems to be in the news here in the States And it was before I left I uploaded a video called cute TCP server design proof of concept. Well as promised Now that I've found a design that I'm happy on I'm going to make a series of tutorials on it I say series because there's just no way I can do all these in one tutorial So this one's gonna be a little bit of explanation and we're gonna actually start the project and then I'm gonna do I'm gonna hope to do like three maybe four videos, but it may take as much as five or six videos to do this If you didn't watch the cute TCP server design proof of concept. It is all about the C10k problem See country product that the C10k problem is all about how to get a TCP server to handle 10,000 connections now I'm gonna preface that with and If you you really should join the Facebook void rums group because those are very good conversation about it and Ryan One of the members in there had a really good thing if you're saying if you need more than 1,000 connections You're doing something wrong and I actually believe that but I like a challenge and when I go through my void rums mailbox Probably 90% of the questions are about TCP and TCP server relations and how things work So if you go out to my website and you look for tutorials, you see it's kind of bear you've got sockets We got how to make a server Multi-threaded q thread pool and then a synchronous So if you're not it really interested in watching the next few videos, but you're kind of curious what it's about I'm going to be showing how to do a synchronous and threading combined and do it correctly Or I should say the cute way of doing it If you're a programmer, you know, there's many many ways of doing anything. So Whoo now Some of the concepts that we've used are signals and slots We've done a basic server application where everything's on the main thread if you try that, you know, it locks up We've tried multi-threads now With multi-threading There's the premise especially if you come from Java that you'll use one thread Per socket. Well threads are very expensive objects to have in memory. So if you start getting upwards of about 50 60 70 100 connections your server is going to start dying on you because it just can't create that many threads the operating system Will stop you and say hey stop what you're doing So then I thought you know, and this was a while ago. I said, ah, I'll try the q thread pool And what a thread pool is is you have a group of threads like say four or five And you'll reuse those threads. So as a connection comes in you'll dump it on a thread in the thread pool So you're never creating more than maybe five or six threads and they just get reused over and over at the problem With that is if you have like say a web server You're only gonna have five six simultaneous connections or however many threads So if you have ten threads in your thread pool, and you have twenty people requesting a file Guess what ten people are gonna get put on hold waiting on the other ten people who are downloading That's just the nature of a thread pool And then there's a synchronous This is actually the real nature if you really want to learn this watch the 70th video It's actually out on my website void realms calm and it's also on YouTube and It's just a synchronous. It's just signals and slots. It's so ridiculously simple. You're gonna go what this is actually a tutorial But yeah, it's actually the nature of how it was designed to be used So I've tried as you can tell I've tried a lot of different models And the model that I really came up with kind of uses a combination of well, you make a thread You dump all these synchronous connections onto that thread now. You also need to buffer Let me promise that you need to buffer the downloads meaning you can't just have 10,000 people downloading at max speed you'll fry your network card not really but you know what I mean You'll you just won't be able to do it your your server will choke and die so you need a way of What's called rate limiting that connection meaning setting it to you will only download at 10k a second You ever notice that you go to like a website not so much YouTube, but like if you're downloading something else and You've got let's say here in the States. I've got I think it's a 10 meg connection And when I go to download something it's not 10 megs per second It'll cap around one or two megs a second. Well, that's actually the server restricting that not Comcast Which don't give me into Comcast. I hate them, but So if you're really interested read the C 10k problem, there is a lot of information in here Now before we really dive in here. I want to make some disclaimers number one as You know Ryan said in the void realms group in Facebook if you're using over a thousand connections You're doing something wrong. I happen to believe that but there may be situations. You want more than that The reason why you'd be doing it wrong is there's these things called load balancers So you have let's say Let's say 5,000 connections coming in at once, right? It'll hit a load balancer, which will pool your servers You'll have multiple servers and it'll say which one of you servers is the least busy and then it throws the connection onto that server So you'd have you know five servers with identical websites on them And it'll just you know the load balancer will send it to the server with the least load on it That's the correct way of doing it But if you're like me and you like a challenge and you're really interested in how this works Well, stay tuned because I'm gonna be going over it in depth Maybe if I can find cute all right here is the actual working code And I'm actually going to start this over from scratch But I wanted to show you guys kind of the premise of what this is gonna look like here It's called VR sockets. I'm just gonna call the project something else But we're gonna have these includes and what we're gonna do here is we're gonna make a TCP server implementation And then from that we're going to inherit and make a HTTP or a web server implementation with a great transfer class Now I would love to just throw the code up here and talk about it But every time I do that people go boo, don't do that. We want to see you type the code So I'm gonna type all this stuff out again and talk about it as we do it just gonna run it just so you can see and In in Linux it kicks out some error that I haven't really had a chance to investigate in Windows it doesn't On my Linux machine it stops at about 1,024 connections The reason for that is something called a you limit or the hard file limit So if you do you limit Dash and in Linux you'll see it's 1,024 which means that's my I think it's a my soft descriptor What it means really is that is the maximum number of files I can open now if you know anything about Linux Unix etc, etc Sockets are considered files So looking at my screen how many files do I have open? Okay now take that number and minus that from 1,024 That's how many sockets I can actually open Also because I'm doing this on my actual computer Rather than having multiple machines and having you know a secondary machine connect to this machine a true client server model That means it's even limited further now you can increase that I just haven't really invested the time and I haven't really figured out how to do that I found some posts on how to do it, but like I said, I just haven't had time on Windows however My Windows 7 box. It's What is it? It's my gaming rig Windows 7 with I think I've got 32 gigs of RAM and it's just Windows 7 professional It's nothing fancy. I Think it was capping out right around 8,000 some odd connections and the reason for that is Windows uses something called IO completion ports which is a completely different animal than how Linux and Unix and all that handle it Under the hood Mac I have not tested on yet, but I'm guessing it's probably got a hard limit similar to Linux and Unix All right, so There is this guy right here are you limit our server is running and This is what's called Siege if you don't know what Siege is you can go out and Google it maybe come on you Siege is a Linux utility Which will put strain on your website in other words, it'll put it under Siege see what I did there So once you've downloaded and install Siege, it's a very easy tool to test with and You just call it and we're gonna say 800 connections and There's the actual server port one two seven zero zero one and we're running on port two thousand because I said so If you try to run on anything lower than port one thousand twenty four You're gonna get you know warning restricted access or it just won't let your program run I think that's actually in most operating systems except for Windows 7 I can't vouch for a window 10 because I hate to say it. I really have no interest in Windows 10 right now So we're gonna put this aside and we're gonna actually Just do this So this is the Siege program hitting my little program here and you can see how it's Really just hammering it and it's getting HTTP one 404 meaning file that found because I really haven't implemented anything. It's actually just requesting the index And we're just gonna let Siege ram right you can see how it's just whipping through here We're gonna control see that and you can see the server just handle 36,849 hits availability 100 percent over 23 seconds Fail transactions zero meaning we had zero dropped whoof Our longest transaction was one second. Well, I'm sorry 1.31 seconds. Our shortest was zero So as you can tell this is a pretty beefy little server platform that we've got here This is scalable and I need to define scalable because depending on who you talk to scalability has a different meaning When I say scalable I mean you can inherit these classes and from the TCP class make an FTP or an HTTP or SSL if you really wanted to go out and get an SSH library because cute really doesn't have it built in then you could do that So I'm kind of running out of steam here. I'm a little bit tired. I switched jobs. So I'm gonna try and do a video every night I can't guarantee that because like I said when you switch jobs, you don't really know What's what's coming from one day to the next? So I Think we're gonna call it quits on this one. I know I said we'd start the project, but we're gonna start it fresh next video Questions comments concerns. I'd love to hear from you Unfortunately, I just cannot keep up with the flood that is YouTube. So go out to Facebook. There is a void realms group in Facebook I try to you know hang out in there once in a while because there's about two two fifty two hundred fifty people in there If you email me good luck my I just give up on my inbox I actually have a separate email account for business just because I can't keep up with it. I try to go in there and Chuck Chuck with the fireworks program if you're listening. I have not forgotten about you, bro. I'm going to get to it I swear I will All right, that's all for this tutorial. Thank you for watching I would say I hope you found this educational entertainment. I really haven't taught you anything That's coming in the next trial