Post on 18-Jan-2017
transcript
No More Mr. Nice Guy
The MEAN Stack
What we will coverFault toleranceScalabilityPerformance
MongodbExpress.jsAngularNode.js(a.k.a. the MEAN stack)
What we won't coverDetailed implementation
Why the MEAN stack?MongodbExpress.jsAngularNode.js
CassandraReactAWS API GatewayPython
Goals of a Highly Available EnvironmentFault toleranceScalablePerformance
Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.-- Rick Cook, The Wizardry Compiled (1989)
Building Our Environment
PM2 { “apps”: [{ “name”: “App1”, “script”: “server.js” “instances”: 0, “max_memory_restart”: “2G” }]}
Node.js
Scaling Node.js
Node.js Node.js Node.js
Elastic Load Balancer
Use The VPC, Luke
Node.js Node.js Node.js
Elastic Load Balancer
Availability Zone CAvailability Zone BAvailability Zone A
Geographical Fault Tolerance
Node.js Node.js Node.js
Elastic Load Balancer
Availability Zone CAvailability Zone BAvailability Zone A
Adding Our MongoDB Servers
MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
Availability Zone CAvailability Zone BAvailability Zone A
MongoDB Fault Tolerance
MongoDB1 MongoDB2 MongoDB3MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
module.exports = { db: 'mongodb://MongoDB1/myApp,MongoDB2/myApp,MongoDB2/myApp', dbOptions: { server: { replset: { rs_name: 'myReplicaSet', readPreference: 'nearest' } }
EuropeUnited StatesChina
Scaling MongoDB
MongoDB1MongoDB1
MongoDB1
MongoDB1MongoDB2
MongoDB2
MongoDB1MongoDB3
MongoDB3MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
EuropeUnited StatesChina
Scaling MongoDB
MongoDB1MongoDB1
MongoDB1
MongoDB1MongoDB2
MongoDB2
MongoDB1MongoDB3
MongoDB3MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
MongoDB || Cassandra || MySql || Postgresql || Couchdb || etc...
Breaking The Bank
Availability Zone CAvailability Zone BAvailability Zone A
MongoDB1 MongoDB2 MongoDB3MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
Breaking The Bank
Availability Zone CAvailability Zone BAvailability Zone A
MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
ELB ($20/month):3 Node.js servers: 3 MongoDB servers:
t2.medium: 2 CPU/ 4GB RAM
$ 20$120$120
$260/month
But How Much Is That… really?
Availability Zone CAvailability Zone BAvailability Zone A
MongoDB3
t2.medium: 2 CPU/ 4GB RAM
MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
500 - 1000 requests per minute
EuropeUnited StatesChina
Scaling Even More...
MongoDB1MongoDB1
MongoDB1
MongoDB1MongoDB2
MongoDB2
MongoDB1MongoDB3
MongoDB3MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
Node.js Node.js
EuropeUnited StatesChina
Scaling Even More...
MongoDB1MongoDB1
MongoDB1MongoDB2
MongoDB1MongoDB3
MongoDB1 MongoDB2 MongoDB3
Node.js
Node.js
Node.js
Elastic Load Balancer
EuropeUnited StatesChina
Scaling Even More...
MongoDB1MongoDB1
MongoDB1
MongoDB1MongoDB2
MongoDB2
MongoDB1MongoDB3
MongoDB3
CDN
MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
EuropeUnited StatesChina
Scaling Even More...
MongoDB1MongoDB1
MongoDB1MongoDB2
MongoDB1MongoDB3
Elasticsearch
Elasticsearch
Elasticsearch
MongoDB1 MongoDB2 MongoDB3
Node.js Node.js Node.js
Elastic Load Balancer
Monitoring
CPU utilization - percentage of time CPU spends doing workCPU load - measure of computational work averaged over timeMemory utilization - percentage of memory allocatedDisk space - amount of disk space allocated vs. availableNetwork throughput - amount of traffic (in bytes)
CPU Wait - indicates time spent by the CPU waiting for resources to come availableCPU Steal - indicates time not available to the CPU due to the underlying host
Monitoring
Monitoring
• Know your goal (MVP or HA)• Monitoring drives direction• Load-test all the things• Learn to forecast expenses
Take-aways
Resources
Links:• http://www.mean.io• https://angularjs.org/• http://expressjs.com/• https://www.mongodb
.org/• http://aws.amazon.co
m/• http://kkovacs.eu/cas
sandra-vs-mongodb-vs-couchdb-vs-redis
Will Button @wfbuttonhttp://willbutton.co
Don’t be jealous that I was at IteratePhx chatting with Will Button all day.