English subtitles

← App Server Scaling - Web Development

Get Embed Code
2 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. Okay so uh,we've taking a fair amount of load off our
  2. database. Now if we were to go through that whole solution,
  3. we'd only be doing database right and we'd very rarely be
  4. doing a database read at all. And this is a big improvement
  5. over doing a database read on every page view. So lets
  6. go back to what our request does. And every request remember
  7. we, we process the request. You know, this was HTTP, URLs
  8. and all that stuff. We did the DB query, the database query.
  9. We collated the results, which for you know, ASCII Chan
  10. or the blog is, there's not really much involved in
  11. that at all. And then, we rendered the HTML. So,
  12. we've improved the database query, but what if we want to improve
  13. these other, other pieces. Yeah, we can use caching to
  14. render HTML. That's definitely a technique there, and we can actually
  15. use another technique for handling all three of these parts
  16. of the requests, which is adding additional app service and this
  17. looks something like this. To date conceptually we've basically had
  18. one program running, that handles all of our requests in
  19. your blog and an ASCII Chan. We've got the simple
  20. program you know, requests come in. Responses come back out, but
  21. if so many requests that one machine can't handle it.
  22. We can do is we can add multiple machines, to take
  23. up some of the load. So all of these extra
  24. requests can go to all of these machines, and these machines
  25. maybe interacting with the database. They may not be. Presumably
  26. they have their little caches that we just implemented that
  27. lives in our program and, and this helps so how
  28. do we get requests to multiple machines. Well, there's a piece
  29. of technology that sits between the user and all of
  30. your app servers called a load balancer. And this is
  31. a special machine, it's a physical machine just like your
  32. app server might be or just like your database server might
  33. be, that's optimized for doing one this, for spreading
  34. requests across multiple machines. So, what happens is, this load
  35. balancer has a list of all of the app servers
  36. that, that are in existence, and requests come in from
  37. the outside world, many, many, many of them. And the
  38. load balancer decides which app server to send the request
  39. to. Send one here, then send one here. Then send
  40. one here. And it can keep going to that process.
  41. And the reason this load balancer can handle all this
  42. traffic while the app servers can't, is the low balancer isn't
  43. doing anything other than taking in the request, choosing a server,
  44. and forwarding the connection along. It doesn't have to parse HTTP
  45. or it may only parse, parse minimal HTTP. It doesn't have
  46. to, it's not doing database queries, it's not rendering HTML, it's
  47. not, going to the cache it's, it's doing almost nothing at
  48. all, other than deciding which server to send a request to.
  49. You've probably won't ever have to write one of these, but it's
  50. good to know how they work. And when you're using App Engine,
  51. Google kind of does all of this for you. They'll automatically create new
  52. servers running your program and and scale. You can actually go into the
  53. app engine admin page and see how many servers they are using
  54. to host your app. Which is pretty cool. Normally this is a
  55. really challenging thing, and not knowing how to do it the first
  56. time, this took me a little while to figure out when we were
  57. scaling Reddit. That doesn't mean I'm not going to make you understand these
  58. things a little bit deeper. So, there are a couple algorithms a
  59. load balancer can use to determine which server to send traffic to.
  60. The simplest one is probably just to randomly choose a server. Now,
  61. a request comes into the load balancer and the load balancer just
  62. picks a server and sends a request there which will, you know,
  63. probably work pretty well. You know, over, over time, if you have
  64. enough requests, each server should get about the same amount of load.
  65. Other approach is round robin, and round robin just means a load
  66. balancer will choose one server at the time. You know, first this guy,
  67. then this guy, then this guy, then this guy, you know, just,
  68. in order. That's also a fairly simple algorithm. And then some of the
  69. balances are really smart and they know what the load is on
  70. each server, how many requests are outstanding at each server, and it may
  71. use some sort of load based algorithm just so you know. This guy's
  72. already handling like five requests and this guy's not doing anything so let's
  73. send, you know, future requests here until, you know, things
  74. even out. There's lots of approaches to doing this. What
  75. I'm going to ask you to do now in the form
  76. of a quiz is implement a basic round robin algorithm.