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