Download presentation
Presentation is loading. Please wait.
Published byCamiel Verbeke Modified over 5 years ago
1
Lecture 10: The Web Server Wednesday February 14, 2018 4/10/2019
2
Specifications Specify what will be done Scenarios
Lecture 10: The Web Server Specifications Specify what will be done Scenarios Lists of features to implement Note optional versus required (priority) Define the user experience Sketches of web pages (not final design) Basically list what should be there as a basis for the design Identify interface to existing systems Servers, databases, etc. Outline of web site and pages List of what pages are needed 4/10/2019
3
Specifications Detail what the application will do
Lecture 10: The Web Server Specifications Detail what the application will do From the programmer’s point of view Can talk about other systems, components, modules More likely to talk about commands, inputs, outputs WHAT not HOW Define the inputs and outputs What information is needed What information is used Where does this information come from Where does this information go Specifications Document due 2/25 4/10/2019
4
Specifications Are Not Designs
Lecture 10: The Web Server Specifications Are Not Designs HOW not WHY Identify particular technologies to use Unless mandated by outside requirements Back ends, front ends, databases, … Identify how tasks are done Front end, back end, database Particular algorithms or processing Provide detailed web site designs Will change as requirements change 4/10/2019
5
Web Applications Front End Web Browser HTTP Database Back End
Lecture 10: The Web Server Web Applications Web Browser Front End HTTP Database Web Server Back End Server Mobile Platform Front End Today we want to preview the next section of the course. 4/10/2019
6
What Services Did You Guess
Lecture 10: The Web Server What Services Did You Guess What does a back end have to do for a web application? Look at prior to class 4/10/2019
7
The Web Server Sits on the host machine
Lecture 10: The Web Server The Web Server Sits on the host machine Listens for connections on a particular port (i.e. 80) Gets HTTP requests sent to that port (via a socket connection) Processes each request independently URL tells it how to process a request Sends a response back on the same socket Basic requests URL with a file specified Find the file on disk and return it Create an appropriate HTTP response (header) Followed by the data in the file 4/10/2019
8
Web Server Game Volunteers (5) to act as clients making requests
Lecture 10: The Web Server Web Server Game Volunteers (5) to act as clients making requests Can request a page of a given color TAN, YELLOW, PURPLE, BLUE, PINK, GREEN Volunteers (5) to act as HTTP connections Interface between clients and server Volunteer (1) to act as the web server Pages reside on file system Set up a “file system” near, but not adjacent to server. Server will probably move to the file system herself. 5 clients Clients should go to web server (stand in line if you need to), ask for a certain color, take it back to their position, wait a random time, and then return color and ask again. 4/10/2019
9
Web Server Game Improvements
Lecture 10: The Web Server Web Server Game Improvements How can we speed this up? Multiple web servers corresponds to multiple threads Putting server near the data corresponds to web cache 4/10/2019
10
Dynamic Requests Static requests are static
Lecture 10: The Web Server Dynamic Requests Static requests are static Don’t work for web applications We need to get different data under different circumstances Based on information passed in with the URL Recall URLs have a query portion With name-value pairs (or POST data) Set up by HTML forms Can involve interaction with JavaScript Web server needs to return different results Based on the query / data 4/10/2019
11
Modified Web Server Game
Lecture 10: The Web Server Modified Web Server Game Client asks for a color and a positive integer <= 100 Web server has to return a sheet giving the square of the number Or ERROR (40x) if the input is illegal Different computation strategies: recruit people to do the computation; do the computation yourself; precompute the values. Ask the web server volunteer how he/she wants to deal with this. 4/10/2019
12
Web Server Game Improvements
Lecture 10: The Web Server Web Server Game Improvements How might we speed this up? Someone else doing the computations (or multiple people for each server) Multiple web servers 4/10/2019
13
Context-Based Requests
Lecture 10: The Web Server Context-Based Requests Most dynamic requests have a context Shopping cart Previous searches Previous inputs and pages User id The web server needs know the context Map users to contexts Use the context in creating the resultant output 4/10/2019
14
Modified Web Server Game
Lecture 10: The Web Server Modified Web Server Game Client asks for a color and provides positive integer <= 100 Server provides the sum of their previous numbers plus the new one Server provides the client with an ID Same ID for same client Client has to return the ID as part of their request What’s wrong here. How will the server remember the client’s sum? One way would be to pass the sum in – this is what a RESTful API might do. Another is to just include some ID for the client and let the server look things up based on that. Server keeps a record of ID->SUM (whiteboard?) This corresponds to context. Need to have an initial call that assigns an ID. What does this break? 4/10/2019
15
Modified Web Server Game
Lecture 10: The Web Server Modified Web Server Game How might we speed this up? How can we speed the server up now? Why not let the client do their own processing? Possibly just ask the server initially for something and then at then end record final values. Could pass in the previous sum as well as the new number. This corresponds to a RESTful interface. Separate server to assign Ids. Split by ID mod # servers. New ones assigned new ID. 4/10/2019
16
What the Web Server Does
Lecture 10: The Web Server What the Web Server Does Given a HTTP Request Return a HTTP Response Given a URL Return the corresponding page Given a URL plus parameters / data Compute and return the resultant data Compute and return a HTML page END OF WEB SERVER GAME 4/10/2019
17
Web Server Issues Handling large numbers of clients
Lecture 10: The Web Server Web Server Issues Handling large numbers of clients Multiple threads, caching, multiple servers Managing context or state Generating HTML output containing computed values Doing the actual computations We need to describe these We need a program (and hence a language) Where are the computations done By the web server Externally 4/10/2019
18
Web Servers General purpose servers
Lecture 10: The Web Server Web Servers General purpose servers Handle static pages; designed to scale Examples: Apache, NginX, Microsoft IIS Extensions to handle Computation Modules: PHP, Ruby, Python, Perl, FCGI, C# External Calls: CGI Special purpose servers TOMCAT: Java servlets NODE.JS: Event-based JavaScript Django, Flask: Python; Ruby on Rails: Ruby Embedded Servers Nanohttpd.java; micro-httpd for arduino NOTE THAT PHP/GWT/templating, etc are in 3/10 lecture. Ruby/Django in 3/13 – we have lots of time to cover these later. Don’t have to be covered here. 4/10/2019
19
Server Organization Server needs to handle multiple requests at once
Lecture 10: The Web Server Server Organization Server needs to handle multiple requests at once Several alternative designs are possible for this Use threads Use multiple servers Use asynchronous I/O Combinations of these 4/10/2019
20
CGI Programs URL: http://host/cgi-bin/cmd?args
Lecture 10: The Web Server CGI Programs URL: cgi-bin is a special directory on the web server cmd is the name of a normal executable in that directory Shell script, perl, php, python, java jar file, c/c++ binary, … args are named arguments passed to command The program ‘cmd’ is run on the web server Any program output is passed back to client Typical Use: Format a request and pass it on to server Problems: efficiency, security, safety Used in very limited applications 4/10/2019
21
PHP PHP is a simple string-oriented scripting language
Lecture 10: The Web Server PHP PHP is a simple string-oriented scripting language Similar capabilities as Python, JavaScript Designed to make string processing easy Web server runs PHP internally As a module or plug-in Automatically when a page has a .php extension We will cover this again later 4/10/2019
22
PHP and HTML What does the web server normally generate HTML pages
Lecture 10: The Web Server PHP and HTML What does the web server normally generate HTML pages With lots of HTML (text) What’s different is based on query part of URL Some fraction of the page Most of the output is fixed text Header, navigation, footer Parts of the contents Why should we write code to output this In any language 4/10/2019
23
PHP Pages Normal URLS where the file has a .php extension
Lecture 10: The Web Server PHP Pages Normal URLS where the file has a .php extension The plug in doesn’t run PHP directly on the file The page is actually a mixture of text and code HTML pages with embedded PHP code PHP module reads the page The HTML portion is passed on directly The PHP code is embedded in <?php … ?> constructs <? … ?> Where the code appears, it is run & replaced by its output PHP print or echo statements This concept, templating, is very useful Used to some extent in React, angular, vue, … 4/10/2019
24
Servlets and JSP Why add a new language Programmers know Java
Lecture 10: The Web Server Servlets and JSP Why add a new language Programmers know Java Back end applications are often written in Java Use Java as the processing language Not ideal for string processing, but acceptable Multiple threads already accommodated Servlet Standard interface invoked directly by URL Path name = class name, parameters accessible Java Server Pages Pages with embedded Java <? … ?> 4/10/2019
25
Java Servlets and JSP Handled by a separate web server
Lecture 10: The Web Server Java Servlets and JSP Handled by a separate web server TOMCAT is the most common Runs on a different port URL: host:8080/servlet/class?parms JSP handled by file extension URL: host:8080/page.jsp 4/10/2019
26
ASP.Net Supported by Microsoft IIS
Lecture 10: The Web Server ASP.Net Supported by Microsoft IIS Use C# (or C++) to write the back end Web pages use templating With embedded C# 4/10/2019
27
Node.JS Why learn a new language (PHP) We already know JavaScript
Lecture 10: The Web Server Node.JS Why learn a new language (PHP) We already know JavaScript PHP is too slow; JavaScript is now compiled and fast It has most of what is needed What’s wrong with Java (C#) Too complex, not string-oriented Too much baggage Straight line code is inefficient Querying database, servers, file system all take time Multiple threads complicate processing Difficult to load balance with diverse threads 4/10/2019
28
Node.JS JavaScript Web Server Separate server (like TOMCAT for Java)
Lecture 10: The Web Server Node.JS JavaScript Web Server Separate server (like TOMCAT for Java) App back end is written in JavaScript Event-Based Computation is done in small pieces Complex interactions are done asynchronously JavaScript code is associated with events The code is executed when the event occurs Code can initiate asynchronous computations with later events Code supplies a continuation invoked when action completes We’ll get back to this next time. 4/10/2019
29
Web Applications Front End Web Browser HTTP Database Back End
Lecture 10: The Web Server Web Applications Web Browser Front End HTTP Database Web Server Back End Server Mobile Platform Front End 4/10/2019
30
Databases Most web applications need to store information
Lecture 10: The Web Server Databases Most web applications need to store information Much of what they do is information based Shopping site as an example The security, integrity, … of the information is important The server code talks to a database system All languages have code to make this relatively easy Database operations Setting up the database Adding and removing information from the database Getting (querying) information from the database 4/10/2019
31
Frameworks All this sounds complex to set up and operate
Lecture 10: The Web Server Frameworks All this sounds complex to set up and operate A lot of the work is common and straightforward Communications, setting up pages, database access, … It can be simplified by extracting these Leaving only the code specific to the particular application Frameworks are attempts to do this Provide common code to plug in the application Provide all the glue code; simplify database access Ruby on Rails, Django, Flask, GWT Express for Node.JS (and other plug-ins) 4/10/2019
32
Next Time Node.JS Homework: Pre-Lab 4 Lecture 10: The Web Server
4/10/2019
33
Server Organization Internal processing Queue of tasks to be done
Lecture 10: The Web Server Server Organization Internal processing Queue of tasks to be done Thread pool to handle multiple requests Internal requests can be queued if necessary Handling initial requests Single thread to read web socket Multithreaded versus Single threaded processing Using non-blocking (asynchronous) I/O 4/10/2019
34
Handling Complex Applications
Lecture 10: The Web Server Handling Complex Applications The web server Can handle PHP, Servlets, etc. But these have limited capabilities These run in limited environments Don’t want to overwhelm the server The server has other responsibilities What if your application is more complex You need to provide complex services (e.g. machine learning, data mining, search) Then you might want to have your own server 4/10/2019
35
User Server Organization
Lecture 10: The Web Server User Server Organization Based on a client-server model Client: app code in the web server Each request is its own client Can be done via PHP or other server side code Socket-based communication Server runs on a host and accepts connections on a port Client connects to that host-port Sends command/request Reads response, processes it to HTML/JSON Returns it to the browser Server: self-standing system Note this is more for CS than design 4/10/2019
36
PHP Language Simple interpreted (scripting) language Untyped
Lecture 10: The Web Server PHP Language Simple interpreted (scripting) language Untyped Basic data types: string, int (long), float (double) Complex data types: associative arrays, classes Lots of built-in functions Good string support “hello $var, this is a ${expr}. “ Good documentation (esp. for libraries) 4/10/2019
37
Node.JS Event Example Request comes in
Lecture 10: The Web Server Node.JS Event Example Request comes in JavaScript code creates database query based on parameters Starts query and registers continuation When query completes (done asynchronously) Continuation is invoked. Template file is opened and a new continuation is provided When file is ready to read (done asynchronously)) A stream from the file to the client is established The file is output asynchronously We’ll get into this in detail next week 4/10/2019
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.