RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Deploying your REST service to DigitalOcean on Ubuntu
Lecture: Configure uWSGI

Login or purchase this course to watch this video and the rest of the course contents.
0:01 The next thing to do is work on the next shell in our onion of configuration, and that is μwsgi, so that's what lives over here in this init folder,
0:10 this auto service.service, so here you can see that we're given a name μwsgi auto service server instance,
0:20 so you can ask like what services are running, things like that ; and then it's going to run μwsgi, we could double check that this path is good,
0:30 yeah, it looks like that's right, so we're going to run or μwsgi and we're going to give it the url here, which I need to figure out what my path is
0:38 one more time, and make sure that production.ini is here, so take this, kind of annoying you got to keep doing this,
0:45 but you got to have it just all wired together correctly, right, and of course, it's going to run in that same folder,
0:52 so we're going to put that like this that's really all we need, we need to set the exact start and we need to set the runtime directory,
0:59 and then everything else is kind of standard, set let me push this again up to our server.
1:04 And it's fine, just like this, ok git pull again, notice we got that fixed,
1:10 so now what we need to do is move that into a particular place on the server where this is going to be used, so hopefully this is all good,
1:17 first of all, before we try to do anything with μwsgi, in terms of like an auto start service, let's just see that this if I take that command
1:26 we're putting into that service file and try to run it that it's going to work; that did not work so well, did it?
1:33 Oh yes, there's one more thing that we're forgetting, that we need to do, so let's pull this back up here,
1:39 so the way this works is μwsgi is going to run this code here, but we need a section in this configuration file that says
1:46 hey μwsgi, when you run, run like this. Alright, so we'll grab this from a previous example,
1:52 here's what we going to need to do, we're going to tell it to listen on that port, we need to set the directory, once again
1:58 I don't know that we really need to set it twice but just to be sure, let's tell it if that is your directory,
2:05 now here's the emperor mode thing I was talking about it's going to run in master and it's going to have five sub processes,
2:10 so basically this is a tradeoff between amount of parallel processing and ram
2:16 in real apps each one of these takes about a 100 megs, 50 to a 100 megs of memory so you can decide how much memory you've got,
2:24 this should work fine for this simple app five, and then enable thread is true as well,
2:29 and if things can a go haywire it will kill off its children services, and you know create them again basically force or restart on them.
2:36 Now let's go make sure we got this log file path correct here, yeah, it looks like it was right, so we are going to use just at the top level
2:44 a single μwsgi log, now everything should be good let's push this up one more time,
2:52 get the latest and let's try again, oh silence is good, why is silence good—
2:57 because everything is going to the log file, so if you see a prompt again here,
3:01 that means it's crashing, and that's bad, you don't want to do crash, right? So let's go and check this out, so if we go to our web apps
3:07 and we go to our log files and we go to our auto service we've got our μwsgi log here, so you can see it's starting up
3:15 and it's just running, in fact let's tail this over like that, and start a third one because we don't yet have this exposed to the internet,
3:25 and do an http local host, now we're running on 8999 so we got this, the data came through, we saw the request,
3:36 we'll do another request, you can see more of these requests coming in nice, and everything's working, you can run it a few more times
3:44 it should pick up speed here in a little bit, there we go. So run that in zero milliseconds, one millisecond, one millisecond,
3:50 notice the first few times it was slow, this is because the primary master μwsgi is sending this off to the sub processes
3:59 and the sub processes haven't yet encountered the templates and things like that, but once they do after a while, this should be nice and fast,
4:06 you can see 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, in the millisecond response time so now they're kind of warmed up, ok,
4:13 so you might notice like the very first little bit of time there is a tiny bit of a slowdown for this,
4:18 but it looks like everything is working, so we can get out of here and we can get out of there, μwsgi is working.
4:25 The next thing we need to configure, the final thing we need to configure is nginx.


Talk Python's Mastodon Michael Kennedy's Mastodon