Outline. 1. Load Testing 2. Frontend Tips 3. Server-side Tips

Similar documents
Microservices with Node.js

Index. Backbone.js app, 274 Behavior-driven development (BDD) language, 252 bodyparser() method, 257

Persistence. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Java with Node.js Powering the Next Generation of Web Applications

Tuesday, January 13, Backend III: Node.js with Databases

NODE.JS SERVER SIDE JAVASCRIPT. Introduc)on Node.js

Backend Development. SWE 432, Fall 2017 Design and Implementation of Software for the Web

END-TO-END JAVASCRIPT WEB APPS

Backend Development. SWE 432, Fall Web Application Development

Persistence & State. SWE 432, Fall 2016 Design and Implementation of Software for the Web

MySQL & NoSQL: The Best of Both Worlds

Tools. SWE 432, Fall Design and Implementation of Software for the Web

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

Improve Web Application Performance with Zend Platform

COMP 2406: Fundamentals of Web Applications. Winter 2014 Mid-Term Exam Solutions

Executive Summary. Performance Report for: The web should be fast. Top 4 Priority Issues

Design and Architecture. Derek Collison

Java vs JavaScript. For Enterprise Web Applications. Chris Bailey IBM Runtime Technologies IBM Corporation

NoSQL & Firebase. SWE 432, Fall Web Application Development

Express.JS. Prof. Cesare Pautasso Modularity

90 Minute Optimization Life Cycle

Chris Bailey Bailey. Emerging Web Application Architectures With Java and Node.js

Module 6 Node.js and Socket.IO

GMusicProcurator Documentation

Squirrel case-study. Decentralized peer-to-peer web cache. Traditional centralized web cache. Based on the Pastry peer-to-peer middleware system

COMP 2406: Fundamentals of Web Applications Winter 2014 Final Exam Solutions Instructor: Anil Somayaji April 24, 2014

Executive Summary. Performance Report for: The web should be fast. Top 1 Priority Issues. How does this affect me?

Cookies, sessions and authentication

More on Testing and Large Scale Web Apps

INF5750. Introduction to JavaScript and Node.js

welcome to BOILERCAMP HOW TO WEB DEV

Locust. Release 0.9.0

Sessions. Mendel Rosenblum. CS142 Lecture Notes - Sessions

Executive Summary. Performance Report for: The web should be fast. How does this affect me?

Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Smashing Node.JS: JavaScript Everywhere

Performance Case Study

Security. CSC309 TA: Sukwon Oh

Beginner's Guide to Performance! Jonathan Rowny

Browser behavior can be quite complex, using more HTTP features than the basic exchange, this trace will show us how much gets transferred.

COMP 2406: Fundamentals of Web Applications. Fall 2013 Mid-Term Exam Solutions

CS 498RK FALL RESTFUL APIs

Human-Computer Interaction Design

MASTERS COURSE IN FULL STACK WEB APPLICATION DEVELOPMENT W W W. W E B S T A C K A C A D E M Y. C O M

CS142 - Web Applications

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

CacheControl Documentation

We are assuming you have node installed!

CS 142 Final Examination

Delivering Large Scale WebRTC. Richard Tworek Principal WebRTC Strategies Twitter: rmtworek. WebRTC STRATEGIES 11/25/2013

MongoDB. CSC309 TA: Sukwon Oh

Jinho Hwang (IBM Research) Wei Zhang, Timothy Wood, H. Howie Huang (George Washington Univ.) K.K. Ramakrishnan (Rutgers University)

WhiteNoise Documentation

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

Seminar on. By Sai Rahul Reddy P. 2/2/2005 Web Caching 1

Scalable applications with HTTP

CIT 668: System Architecture. Caching

Client Side JavaScript and AJAX

CSc 337 LECTURE 16: WRITING YOUR OWN WEB SERVICE

Databases and Big Data Today. CS634 Class 22

Red Hat Mobile Application Platform Hosted 3

IDWedgeKB Serial Port and NodeJS

Scalability of web applications

Masters in Web Development

Adaptive SMT Control for More Responsive Web Applications

Gen Z demands instant gratification

CACHE ME IF YOU CAN! GETTING STARTED WITH AMAZON ELASTICACHE. AWS Charlotte Meetup / Charlotte Cloud Computing Meetup Bilal Soylu October 2013

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

IERG Tutuorial 5. Benedict Mak

Developer Internship Opportunity at I-CC

Node.js. Node.js Overview. CS144: Web Applications

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues

Goals. Facebook s Scaling Problem. Scaling Strategy. Facebook Three Layer Architecture. Workload. Memcache as a Service.

Hybrid mobile application with Ionic and MEAN stack

Let s say that hosting a cloudbased application is like car ownership

MySQL Performance Optimization and Troubleshooting with PMM. Peter Zaitsev, CEO, Percona

Who am I? Weibo:

Distributed Architectures & Microservices. CS 475, Spring 2018 Concurrent & Distributed Systems

Flash: an efficient and portable web server

a Very Short Introduction to AngularJS

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

Which compute option is designed for the above scenario? A. OpenWhisk B. Containers C. Virtual Servers D. Cloud Foundry

Building a Scalable Architecture for Web Apps - Part I (Lessons Directi)

this presentation code is on

CSE 333 Lecture HTTP

Practical Node.js. Building Real-World Scalable Web Apps. Apress* Azat Mardan

Millisort: An Experiment in Granular Computing. Seo Jin Park with Yilong Li, Collin Lee and John Ousterhout

PaaS Cloud mit Java. Eberhard Wolff, Principal Technologist, SpringSource A division of VMware VMware Inc. All rights reserved

Drupal Frontend Performance & Scalability

Web Application Development

Architecture and Design of MySQL Powered Applications. Peter Zaitsev CEO, Percona Highload Moscow, Russia 31 Oct 2014

Scaling Pinterest. Marty Weiner Level 83 Interwebz Geek

Which application/messaging protocol is right for me?

High Performance Drupal

Web Application Development

mongodb-tornado-angular Documentation

1

Transcription:

Performance

Outline 1. Load Testing 2. Frontend Tips 3. Server-side Tips

Load Testing Load testing is the process of putting demand on a system or device and measuring its response. Load testing is performed to determine a system's behavior under both normal and anticipated peak load conditions.

Load Testing in High Level Purpose Predict how your application will perform when a large number of users are using your application at the same time How? Simulate artificial but realistic workloads

Load Testing Tools JMeter o Tsung o Free and written in Java Free and written in Erlang loader.io o Partially free; integrates with Heroku locust.io o Free and written in Python (Today s Focus)

locust.io Advantages Write simple Python code to simulate a user behaviour Handles thousands of users on a single machine Disadvantages Results are downloadable in CSV format

locust.io Installation pip install locustio

locust.io Every HTTP connection will open a new file, but OS sets a limit for the max # of files that can be opened. You need: # max open files >= # of user you want to test Linux ulimit - Sn <# max open files> <- works up to ~64,000 Make sure to do this for both terminals running express.js and locust.io!!!

locust.io 1. Simulating a user Write a class subclassing HttpLocust to define a user.

Example class User(HttpLocust): task_set = UserTasks min_wait = 5000 max_wait = 15000 Explanation: A user s behaviour will be defined in UserTasks class. The user will wait randomly between 5 to 15 secs before sending a request to the application.

Example class UserTasks(TaskSet): @task(2) def index(self): self.client.get( / ) @task(1) def about(self): self.client.get( / about/ ) Explanation: A user will randomly send a GET request to / endpoint and a GET request to /about/ endpoint. The user will send GET requests to / about twice as many times as GET requests to /about/.

locust.io Web Interface

locust.io Web Interface

Demo

Front-end Tips 1. gzip 2. cache control

gzip in express.js Use compress middleware (Version 3.x) app.use(express.compress()); Use compression middleware (Version 4.x) var compress = require( compression ); app.use(compress());

Cache Control HTTP Header You can tell a user s browser to cache specific resources from your application o e.g. images, js files, css files, etc Reduce latency o a user will receive response faster Reduce network bandwidth o a network can handle more messages

Cache Control Useful headers max-age=[seconds] o max amount of time a resource will be considered fresh no-cache o forces server validation before releasing a cached copy no-store o disable caching a resource public/private o allow/disable caching a response to a public (shared) cache

Cache Control What happens if a resource seems stale? o o Cache will try to validate its copy against your application Uses Last-Modified or ETags header

Last-Modified How it works

ETags How it works ETag usually computes a hash of a resource to detect any changes made to it.

Cache Control in express.js Good News! o They are mostly built-in or easy to use!

Cache Control in express.js Static Files o Use express.static() with maxage option Example app.use(express.static( dirname + /public, { maxage: 86400000 }));

Cache Control in express.js favicon o serve-favicon module Example var favicon = require( serve- favicon ); app.use(favicon(path.join( dirname, public, favicon.ico ), {maxage: 86400000}));

Cache Control in express.js ETags express.js calculates ETags automatically However, if you want to customize it app.set( etag, function(body, encoding) { return calculatehash(body, encoding); });

Cache Control in express.js response.send() does automatic cache control support http://expressjs.com/api.html for more information But you can always set these headers manually!

Backend Tips 1. Increase parallelism of node.js 2. Caching 3. DB index

Node.js Asynchronous + single threaded o o Almost all computers are multi-core now node.js (express.js) uses only 1 core by default! Solution? o Run one node.js process per core of your machine

Cluster module cluster module makes your job of managing multiple node.js processes easier. https://nodejs.org/api/cluster.html for more information

Cluster module var cluster = require( cluster ); var numcpus = require( os ).cpus().length; if (cluster.ismaster) { for (var i = 0; i < numcpus; i++) cluster.fork(); } else { var app = require( express )(); app.get( /, function(req, res) {..}); app.listen(3000); }

Handling failures if (cluster.ismaster) { for (var i = 0; i < numcpus; i++) cluster.fork(); cluster.on( exit, function(worker) { cluster.fork(); }); }

Caching Basic Idea: Cache resources that are costly to generate and frequently read and rarely modified Options: Redis, Memcached, Varnish,...

Caching with Redis Key-value cache/store known to be very very fast! http://redis.io/ Idea: o Store results from expensive computation in Redis for quick reuse (avoid computation)

Using Redis Installation instruction in http://redis.io/download Provides node.js driver similar to MongoDB o npm install redis

Example app.get( /expensive, function(req, res) { var result = 0; for(var i = 0; i < 100000; i++) {..} res.send(result); });

Example var redis = require( redis ); var client = redis.createclient(); app.get( /expensive, function(req, res) { client.get( result, function(err, val) { if (val) return res.send(val); else { var result = 0; for(var i=0; i<10000; i++) {..} client.set( result, result); } }); });

MongoDB Index Lets you avoid scanning every document in a collection Speeds up your read operations However, they may hurt your write operations o Because it needs to write more data

MongoDB Index Indexes are just data structures that stores specific field values in sorted order Example db.collection( collection ).createindex( {field: 1} );