CS174
Chris Pollett
Nov 30, 2020
ab -nSOME_NUM -cCONCURRENCY URL
|fg5:search_yioop:105>ab -n2000 -c3 "http://localhost/git/yioop/?q=google" This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.24 Server Hostname: localhost Server Port: 80 Document Path: /git/yioop/?q=google Document Length: 328 bytes Concurrency Level: 3 Time taken for tests: 1.199 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Non-2xx responses: 1000 Total transferred: 553000 bytes HTML transferred: 328000 bytes Requests per second: 834.27 [#/sec] (mean) Time per request: 3.596 [ms] (mean) Time per request: 1.199 [ms] (mean, across all concurrent requests) Transfer rate: 450.54 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 3 59.1 0 1084 Processing: 0 0 0.1 0 1 Waiting: 0 0 0.1 0 1 Total: 0 4 59.2 0 1085 Percentage of the requests served within a certain time (ms) 50% 0 66% 0 75% 0 80% 0 90% 0 95% 0 98% 1 99% 1 100% 1085 (longest request)
Which of the following statements is true?
Array( "name" => "Bob", ..., "posts" => Array([0] => Array("title" => "Dark and Stormy Night", ...), [1]=>...))
sudo apt install nodejs
brew install node
> a = 10 10 > a + 5 15 > console.log('yo') yo undefined > .help .break Sometimes you get stuck, this gets you out .clear Alias for .break .editor Enter editor mode .exit Exit the repl .help Print this help message .load Load JS from a file into the REPL session .save Save all evaluated commands in this REPL session to a file > .exit
var http = require('http'); // module pattern object for creating a server // If want ssl use require('https') and add key info http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); // 1st arg is HTTP response type, 2arg is HTTP headers as JSON object response.end('Node is working\n'); // body of response }).listen(8888); console.log("Server is up!");
var http = require('http'); var fs = require('fs'); http.createServer(function (request, response) { var name = require('url').parse(request.url, true).query.name; // gets name from the query string if (name === undefined) { name = "myphoto"; } if (name == 'myphoto') { var file_name = name + '.jpg'; fs.stat(file_name, function (error, status) { //callback when promise ready. I.e., have stat info about file if (error) { console.error(error); response.writeHead(404, {'Content-Type': 'text/plain'}); response.end("myphoto.jpg not available!"); } else { var image = fs.readFileSync(file_name); response.contentType = 'image/jpeg'; //alternative was to set Content-Type response.contentLength = status.size; response.end(image, 'binary'); // send JPEG photo } }); } else { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Name was:' + name); } }).listen(8888); console.log("Server is up!");
On Linux: sudo apt install npm On Mac: brew install npm
sudo npm install some_package
sudo npm update -g
mkdir webapp cd webapp
npm init // bunch of prompts, use default, except entry point: (index.js)
npm install express --save
var express = require('express') var app = express() // can add different routes app.get('/', function (req, res) { res.send('This is an express app using route /') }) app.listen(8888, function () { console.log('Server up!') })
We can then run the project by typing at a shell prompt:
node index.js