Creating a node.js application is simple enough.
var app = require('express')(); app.get('/',function(req,res){ res.send("Hello world!"); });
But suppose people became obsessed with your Hello World!
application and exhausted your resources. How could this example be scaled up on practice? I don't understand it, because yes, you could open several node.js instance in different computers - but when someone access http://your_site.com/ it aims directly that specific machine, that specific port, that specific node process. So how?
The asynchronous feature is what makes the single-thread of the Node. js program quite efficient. It makes the program fast and scalable without using as many resources as a multi-threaded application. Naturally, this makes Node a good fit for data-intensive and I/O intensive programs.
Node. js can be used to build both simple and advanced fintech applications that require a lot of data processing real-time communication. Node's scalable features make it perfect for this kind of application.
A distributed system contains multiple nodes that are physically separate but linked together using the network. All the nodes in this system communicate with each other and handle processes in tandem. Each of these nodes contains a small part of the distributed operating system software.
There are many many ways to deal with this, but it boils down to 2 things:
For the first option, you can user node-cluster
or the same solution as for the seconde option. node-cluster
(http://nodejs.org/api/cluster.html) essentially is a built in way to fork the node process into one master and multiple workers. Typically, you'd want 1 master and n-1 to n workers (n being your number of available cores).
The second option is to use a load balancer that distributes the requests amongst multiple workers (on the same server, or across servers).
Here you have multiple options as well. Here are a few:
upstream
server)One more thing, once you start having multiple processes serving requests, you can no longer use memory to store state, you need an additional service to store shared states, Redis (http://redis.io) is a popular choice, but by no means the only one.
If you use services such as cloudfoundry, heroku, and others, they set it up for you so you only have to worry about your app's logic (and using a service to deal with shared state)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With