- Make restful server scalable so that data transfer / synchronization can be more efficient.
- Added pm2 as the load balancer.
- Used
Snowflake
like algorithm to make task id unique in all clusters, but it's simplified.
How to make the synchronization process between devices efficient? / How to optimize network bandwidth usage?
Solutions:
- Make the restful server scalable so that read/writes requests can be redirected to different servers.
- Use Http/v2 over Http/v1.
- Compress server requests/responses.
- Only send necessary data to servers instead of complete / large objects.
- Asynchronous over Synchronous
...(So many ways)
Solutions:
- Use correct distribution solutions.
- Make application servers stateless as much as possible.
- If the loads to server is huge consider using
Queues
(ActiveMQ, SQS etc). - Make data modification atomic (Thread safe, redis, memcache etc).
- Data sharding.
...Etc
- Clone the repo.
yarn
ornpm i
to install dependencies.Optional
If you want to monitor clusters status, better to runnpm i pm2 -g
In the project directory, you can run:
Start the restful server clusters and load balancer, the default value of clusters amount is 4.
The load balancer server port can be changed in src/config.js
The restful servers can be scaled very easily, just need to change the REST_INSTANCES=4
.
As the load balancer is stateless, so the load balancer server can also be scaled easily.
Due to the configuration for now, the load balancer is scaled based on the number of the CPUs.
Runs the app in the development mode. Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits. You will also see any lint errors in the console.
Launches the data store test runner with jest.