Scalable Cloud Solutions
with Node.js
Aaron Michael König & Mathias Peter
Team Centric Software
Foto: JD Hancock CC BY 2.0
Mathias Peter
mp@tcs.de

8+ years experience

JS, Redis, AWS



! mpneuried
Aaron Michael König
amk@tcs.de

10+ years expe...
Team Centric Software
• Webapps & native mobile apps

• Amazon Web Services since 2007

• Redis & Node.js since 2010
Node.js since the early days
Node.js since the early days
• Node.js in production since 0.4
Node.js since the early days
• Node.js in production since 0.4
• Developed many building blocks in Node.js
Node.js since the early days
• Node.js in production since 0.4
• Developed many building blocks in Node.js
• Many microser...
Node.js since the early days
• Node.js in production since 0.4
• Developed many building blocks in Node.js
• Many microser...
Node.js in customer projects
Cloud based setup.Electronic fitness devices.
Software in a health club?
Advanced electronic fitness devices?
Foto: JD Hancock CC BY 2.0
Software in a health club?
Advanced electronic fitness devices?
WAT?
Foto: JD Hancock CC BY 2.0
Training the “old way”
Training plan
Training the “old way”
Training plan
Training the “old way”
Training plan Training plan
Training the “old way”
Training the “milon way”
Training the “milon way”
☁️
Training the “milon way”
Training plan
☁️
Training the “milon way”
Training plan
milon care device logins
Scalability
Foto: JD Hancock CC BY 2.0
Bilder?
Asynchronous TasksSynchronous Tasks
Foto: JD Hancock CC BY 2.0
Scaling for synchronous tasks
• more servers

• better hardware

• storage

• Autoscaling
Scaling for synchronous tasks
Load
Balancer
Redis
MySQL
MySQL
S3 DynamoDB
EC2 Instances
Scaling for synchronous tasks
Load
Balancer
Redis
MySQL
MySQL
S3 DynamoDB
EC2 Instances
Autoscale
Scaling for synchronous tasks
Load
Balancer
Redis
MySQL
MySQL
S3 DynamoDB
EC2 Instances
Processing
Autoscale
Scaling for synchronous tasks
Load
Balancer
Redis
MySQL
MySQL
S3 DynamoDB
EC2 Instances
Scaling for asynchronous tasks
Queueing
• Logs

• Training archiving

• Training results

• Statistics

• House keeping

• Achievements
Scaling for asynchronous t...
Advantages of Queueing
Advantages of Queueing
• Asynchronous Execution

• Distribution of work

• Reliability

• Guaranteed success or failure
Queueing
… or how a queue should work
Foto: JD Hancock CC BY 2.0
Queue
create queue
message D
Queue
message C
message B
message A
create queueadd messages …
message D
Queue
message C
message B
message A
create queueadd messages …
Worker
create a worker
Worker
message D
Queue
message C
message B
message Acopy
receive and …
message A
Worker
message D
Queue
message C
message B
message Acopy
receive and …
message A
process
invisible for 30s
Worker
message D
Queue
message C
message B
delete on success
message A message Acopy
Worker
message D
Queue
message C
message B
delete on success
Worker
Queue
message D
message C
message Bcopy
receive and …
message B
Worker
Queue
message D
message C
message Bcopy
receive and …
message B
process
invisible for 30s
Worker
Queue
message D
message C
message B message Bcopy
Worker
Queue
message D
message C
💩 ERROR !
message B
Worker
message Bcopy
Worker
Queue
message D
message C
message B
… remain within stack
Wait … SCALING !
Foto: JD Hancock CC BY 2.0
Queue
message D
multiple workers 👍
Worker
message Ccopymessage C
Worker
message Bcopymessage B
Work
er
Work
er
Worker
Work...
Queue
message D
multiple workers 👍
Worker
message Ccopy
message C
Worker
message Bcopymessage B
Work
er
Work
er
Worker
Wor...
Redis Simple Message Queue
RSMQ made by
npm install rsmq
Design concept
Simple & Fast
Only Redis - No management server
Guaranteed delivery to a single recipient
Visibility timeout for received ...
How to …
Foto: JD Hancock CC BY 2.0
rsmq.createQueue({qname:"foo", vt:30}, function(err, created){
// ...
});
create
rsmq.createQueue({qname:"foo", vt:30}, function(err, created){
// ...
});
rsmq.sendMessage({qname:"foo", message:"bar"}, f...
rsmq.createQueue({qname:"foo", vt:30}, function(err, created){
// ...
});
rsmq.sendMessage({qname:"foo", message:"bar"}, f...
rsmq.createQueue({qname:"foo", vt:30}, function(err, created){
// ...
});
rsmq.sendMessage({qname:"foo", message:"bar"}, f...
Foto: JD Hancock CC BY 2.0
Foto: JD Hancock CC BY 2.0
npm install rsmq-worker
How to …
Foto: JD Hancock CC by 2.0
var RSMQWorker = require( "rsmq-worker" );
var worker = new RSMQWorker( "foo" ); // poll the "foo" queueinit
var RSMQWorker = require( "rsmq-worker" );
var worker = new RSMQWorker( "foo" ); // poll the "foo" queue
worker.on("messag...
var RSMQWorker = require( "rsmq-worker" );
var worker = new RSMQWorker( "foo" ); // poll the "foo" queue
worker.on("messag...
var RSMQWorker = require( "rsmq-worker" );
var worker = new RSMQWorker( "foo" ); // poll the "foo" queue
worker.on("messag...
DEMO
Foto: JD Hancock CC by 2.0
Demo results
1x worker.js 4x worker.js
performance
> 250%
Lightweight

just redis

No overhead

trusted environments only, no security

Fast

depends on redis
Features
Want more?
Terminal Client
RSMQ
rest-interface
REST Interface
For PHP, ASP, Curl …
rsmq-cli (under dev.)
RSMQ
cli
Monitori...
Questions?
Foto: JD Hancock CC by 2.0
Team Centric Software:
http://www.tcs.de/
RSMQ:
! http://smrchy.github.io/rsmq/
RSMQ...
RabbitMQ

management server

Kue

too complex and not lightweight

SQS

only AWS, higher latency

Redis-List

we need more...
Scalable Cloud Solutions with Node.js
Scalable Cloud Solutions with Node.js
Scalable Cloud Solutions with Node.js
Scalable Cloud Solutions with Node.js
Scalable Cloud Solutions with Node.js
Nächste SlideShare
Wird geladen in …5
×

Scalable Cloud Solutions with Node.js

938 Aufrufe

Veröffentlicht am

Solutions to scale a Node.js projects in the cloud. In detail it'll show a queueing solution based on redis and Node.js.

Veröffentlicht in: Software
0 Kommentare
1 Gefällt mir
Statistik
Notizen
  • Als Erste(r) kommentieren

Keine Downloads
Aufrufe
Aufrufe insgesamt
938
Auf SlideShare
0
Aus Einbettungen
0
Anzahl an Einbettungen
3
Aktionen
Geteilt
0
Downloads
7
Kommentare
0
Gefällt mir
1
Einbettungen 0
Keine Einbettungen

Keine Notizen für die Folie

Scalable Cloud Solutions with Node.js

  1. 1. Scalable Cloud Solutions with Node.js Aaron Michael König & Mathias Peter Team Centric Software Foto: JD Hancock CC BY 2.0
  2. 2. Mathias Peter mp@tcs.de 8+ years experience
 JS, Redis, AWS
 
 ! mpneuried Aaron Michael König amk@tcs.de 10+ years experience
 JS, iOS, C#
 
 ! exinferis
  3. 3. Team Centric Software • Webapps & native mobile apps • Amazon Web Services since 2007 • Redis & Node.js since 2010
  4. 4. Node.js since the early days
  5. 5. Node.js since the early days • Node.js in production since 0.4
  6. 6. Node.js since the early days • Node.js in production since 0.4 • Developed many building blocks in Node.js
  7. 7. Node.js since the early days • Node.js in production since 0.4 • Developed many building blocks in Node.js • Many microservices on Node.js
  8. 8. Node.js since the early days • Node.js in production since 0.4 • Developed many building blocks in Node.js • Many microservices on Node.js • Released quite a few open source modules over the years
  9. 9. Node.js in customer projects
  10. 10. Cloud based setup.Electronic fitness devices.
  11. 11. Software in a health club? Advanced electronic fitness devices? Foto: JD Hancock CC BY 2.0
  12. 12. Software in a health club? Advanced electronic fitness devices? WAT? Foto: JD Hancock CC BY 2.0
  13. 13. Training the “old way”
  14. 14. Training plan Training the “old way”
  15. 15. Training plan Training the “old way”
  16. 16. Training plan Training plan Training the “old way”
  17. 17. Training the “milon way”
  18. 18. Training the “milon way”
  19. 19. ☁️ Training the “milon way” Training plan
  20. 20. ☁️ Training the “milon way” Training plan
  21. 21. milon care device logins
  22. 22. Scalability Foto: JD Hancock CC BY 2.0
  23. 23. Bilder? Asynchronous TasksSynchronous Tasks Foto: JD Hancock CC BY 2.0
  24. 24. Scaling for synchronous tasks • more servers • better hardware • storage • Autoscaling
  25. 25. Scaling for synchronous tasks Load Balancer Redis MySQL MySQL S3 DynamoDB EC2 Instances
  26. 26. Scaling for synchronous tasks Load Balancer Redis MySQL MySQL S3 DynamoDB EC2 Instances
  27. 27. Autoscale Scaling for synchronous tasks Load Balancer Redis MySQL MySQL S3 DynamoDB EC2 Instances
  28. 28. Processing Autoscale Scaling for synchronous tasks Load Balancer Redis MySQL MySQL S3 DynamoDB EC2 Instances
  29. 29. Scaling for asynchronous tasks Queueing
  30. 30. • Logs • Training archiving • Training results • Statistics • House keeping • Achievements Scaling for asynchronous tasks Queueing
  31. 31. Advantages of Queueing
  32. 32. Advantages of Queueing • Asynchronous Execution • Distribution of work • Reliability • Guaranteed success or failure
  33. 33. Queueing … or how a queue should work Foto: JD Hancock CC BY 2.0
  34. 34. Queue create queue
  35. 35. message D Queue message C message B message A create queueadd messages …
  36. 36. message D Queue message C message B message A create queueadd messages … Worker create a worker
  37. 37. Worker message D Queue message C message B message Acopy receive and … message A
  38. 38. Worker message D Queue message C message B message Acopy receive and … message A process invisible for 30s
  39. 39. Worker message D Queue message C message B delete on success message A message Acopy
  40. 40. Worker message D Queue message C message B delete on success
  41. 41. Worker Queue message D message C message Bcopy receive and … message B
  42. 42. Worker Queue message D message C message Bcopy receive and … message B process invisible for 30s
  43. 43. Worker Queue message D message C message B message Bcopy
  44. 44. Worker Queue message D message C 💩 ERROR ! message B Worker message Bcopy
  45. 45. Worker Queue message D message C message B … remain within stack
  46. 46. Wait … SCALING ! Foto: JD Hancock CC BY 2.0
  47. 47. Queue message D multiple workers 👍 Worker message Ccopymessage C Worker message Bcopymessage B Work er Work er Worker Worker
  48. 48. Queue message D multiple workers 👍 Worker message Ccopy message C Worker message Bcopymessage B Work er Work er Worker Worker
  49. 49. Redis Simple Message Queue RSMQ made by npm install rsmq
  50. 50. Design concept
  51. 51. Simple & Fast Only Redis - No management server Guaranteed delivery to a single recipient Visibility timeout for received messages Design concept
  52. 52. How to … Foto: JD Hancock CC BY 2.0
  53. 53. rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... }); create
  54. 54. rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... }); rsmq.sendMessage({qname:"foo", message:"bar"}, function(err){ // ... }); create send
  55. 55. rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... }); rsmq.sendMessage({qname:"foo", message:"bar"}, function(err){ // ... }); rsmq.receiveMessage({qname:"foo"}, function(err, message){ // ... { id: "42abc", message: "bar", rc: 1, ... } }); create send receive
  56. 56. rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... }); rsmq.sendMessage({qname:"foo", message:"bar"}, function(err){ // ... }); rsmq.receiveMessage({qname:"foo"}, function(err, message){ // ... { id: "42abc", message: "bar", rc: 1, ... } }); create send receive rsmq.deleteMessage({qname:"foo", id: msgid}, function(err, success){ // ... }); delete
  57. 57. Foto: JD Hancock CC BY 2.0
  58. 58. Foto: JD Hancock CC BY 2.0 npm install rsmq-worker
  59. 59. How to … Foto: JD Hancock CC by 2.0
  60. 60. var RSMQWorker = require( "rsmq-worker" ); var worker = new RSMQWorker( "foo" ); // poll the "foo" queueinit
  61. 61. var RSMQWorker = require( "rsmq-worker" ); var worker = new RSMQWorker( "foo" ); // poll the "foo" queue worker.on("message", function(message, next, msgid){ // ... processing next(); // on error use: next( err ); }); init listen
  62. 62. var RSMQWorker = require( "rsmq-worker" ); var worker = new RSMQWorker( "foo" ); // poll the "foo" queue worker.on("message", function(message, next, msgid){ // ... processing next(); // on error use: next( err ); }); worker.start(); init listen start
  63. 63. var RSMQWorker = require( "rsmq-worker" ); var worker = new RSMQWorker( "foo" ); // poll the "foo" queue worker.on("message", function(message, next, msgid){ // ... processing next(); // on error use: next( err ); }); worker.start(); init listen start worker.send(„bar"); // send to "foo"send
  64. 64. DEMO Foto: JD Hancock CC by 2.0
  65. 65. Demo results 1x worker.js 4x worker.js performance > 250%
  66. 66. Lightweight
 just redis No overhead
 trusted environments only, no security Fast
 depends on redis Features
  67. 67. Want more? Terminal Client RSMQ rest-interface REST Interface For PHP, ASP, Curl … rsmq-cli (under dev.) RSMQ cli Monitoring Usage charts rsmq-monitor (planned) RSMQ monitor Notification Engine Email Buffer
  68. 68. Questions? Foto: JD Hancock CC by 2.0 Team Centric Software: http://www.tcs.de/ RSMQ: ! http://smrchy.github.io/rsmq/ RSMQ-worker: ! https://github.com/mpneuried/rsmq-worker Demo-Source: ! https://github.com/mpneuried/rsmq-mnug-demo Images: Thanks to JD Hancock for providing CC licensed images Credits
  69. 69. RabbitMQ
 management server Kue
 too complex and not lightweight SQS
 only AWS, higher latency Redis-List
 we need more than that Why not use …?

×