parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.84k stars 4.77k forks source link

Scaling Parse Server #244

Closed gateway closed 8 years ago

gateway commented 8 years ago

So with all the new stuff coming out where the team at Parse is converting their GO version of the Parse server to Node.js I would like to hear from the Parse team on the best way we can scale horizontally. I havent used Node.js in some time and I know their are some packages to help scale but I would like to get some professional advice on how this would work, how to deploy code across the server, how to deal with cloud code etc.. is it set up to scale?

Here are some things I have found but not personally used.

The idea is to make sure that each serve can handle x amount of requests and you probably need to have a load balancer/s (for fail over) in front to check the health and send the request to each parse server.

Anyhow I'm curious if anyone has any thoughts on this?

duergner commented 8 years ago

The easiest approach I found so far for scaling NodeJS instance is the following setup:

Loadbalancer incl. SSL termination (HAProxy or ELB if on AWS) -- balance between multiple hosts --> NGinX (Gzip & Cache) -- balance between multiple NodeJS instances --> one NodeJS instance per CPU hard bound to a single CPU

gateway commented 8 years ago

@duergner thanks for the info.. the last stack I built was basically 2 haproxy's (one for fail over) a stack of node.js servers then couchbase as the database. One thing to consider with the node.js stack and a process running on each cpu core is the amount of requests that the actual server can handel, this is where you get deep into sysctrl settings which can be a big pain. I'm personally trying to avoid building this system again due to limited resources on my side but it would be good to hear peoples advice. I might try to set up a aws full stack this weekend and run some benchmarks with Jmeter/Apache Benchmark etc... Also another thing is making sure your database can scale.

While not a walk though or full howto this was a decent article posted last about scaling.. http://highscalability.com/blog/2016/1/11/a-beginners-guide-to-scaling-to-11-million-users-on-amazons.html I just hope the parse-server can scale, and on top of that we should all be running profiling tools to see where performance bottle necks are.

Copyrightsworld commented 8 years ago

Stupid question: Scaling PS via Heroku ?

gateway commented 8 years ago

Potential alternative to Heroku.. http://mobile.awsblog.com/post/TxCD57GZLM2JR/How-to-set-up-Parse-Server-on-AWS-using-AWS-Elastic-Beanstalk

flovilmart commented 8 years ago

You can also use google app engine, as they support autoscaling node etc... It would end up being a containerized docker.

I am wondering about the statelessness of the system, maybe some data would need to be shared across servers for optimization (memcached/redis) like a cache for active users and sessions etc..

gateway commented 8 years ago

@flovilmart I have tried them all, Heroku, GCloud, AWS.. I had such a headache with GCloud and some how spun up several servers etc.. I followed the docs but was a pain.. others might have different opinions.

flovilmart commented 8 years ago

@gateway, The doc is pretty bad indeed, but auto scaling is configured in the app.yaml. Would you want an example?

gateway commented 8 years ago

@flovilmart I'm leaning more towards aws system with maybe mongo db cloud interface to deploy mongo db's into aws that gives me visual overview of the database, backup and scaling..

So Elastic Bean Stalk running some c4.large parse servers, then 2-3 mongodb managed by mongo cloud, with the newrelic plugin to monitor all servers, transaction traces.. etc

gateway commented 8 years ago

Anyone used cluster in node.js on aws servers? I'm looking at using some c4.large boxes with the elastic beanstalk system and they are specked with 2 vCPU's and since node.js runs on one thread ideally in this case it could launch and use both thread on this box. Any thoughts, feedback or suggestions on if this is a good approach and if show how would one set this up since I never messed with cluster

OliverNicolini commented 8 years ago

@gateway you can use pm2 with cluster mode

gateway commented 8 years ago

@OliverNicolini could you explain how I would do this, let's say I have 2 cores on a server how would I use this? Also I assuming I need to limit the amount of memory used in the server to make sure the OS can still run. What about if a node.js instance crashes ?

OliverNicolini commented 8 years ago

@gateway First install pm2: sudo npm install -g pm2 Then make sure it will restart if the system reboot by typing: sudo pm2 startup Then start parse server like this: pm2 start pm2_parse.json with pm2_parse.json like the following:

{
  "apps" : [
                  {
                        "name"            : "parse-server",
                        "cwd"               : "path/to/parse-server/",
                        "script"             : "index.js",
                        "log_date_format"  : "YYYY-MM-DD HH:mm Z",
                        "instances"        :  2, \\ number of cores,
                        "max_memory_restart":  "100M",
                        "exec_interpreter" : "node",
                        "exec_mode"        : "cluster",
                        "autorestart"          : true
                 }
              ]
}

This will spawn 2 instances of your parse server restart them if they reach 100Mb of memory as well as restarting them if they crash.

gateway commented 8 years ago

@OliverNicolini thanks man! Ill test this out.. is their a rule of thumb on cpu cores and node.js instances? meaning if I have 4, should I do 3 node.js instances to keep one core for the OS?

campers commented 8 years ago

I'm building a Java/Kotlin app using the Google cloud api's to provision a Mongo server with persistent disk and node.js servers in an auto-scaling group on Compute Engine.

15% - 40% cheaper on Google cloud than AWS by their numbers, which makes it way cheaper than Heroku, even with a reasonable network egress allowance.

http://googlecloudplatform.blogspot.com.au/2016/01/Happy-New-Year-from-Google-Cloud-Platform-still-the-price-performance-leader-in-public-cloudom-google-cloud.html

kenglou commented 8 years ago

Is Google Cloud Accessible by China Market?

campers commented 8 years ago

Not sure, this article says HTC uses the google cloud everywhere except China where it uses Azure http://www.businessinsider.com.au/htc-chooses-google-cloud-platform-over-amazon-alibaba-2015-6?r=US&IR=T

kenglou commented 8 years ago

Ya, previously i use Google App Engine and found that it don't have accessibility in china, and that's the pain. I wish to know more about accessibility of those cloud/server provider around the world.

Copyrightsworld commented 8 years ago

Ok, but will adding more web Dynos on my heroku sever actually scale my Parse server so it can servers more and more requests?

carmenlau commented 8 years ago

Would like to know about the statelessness of the parse server too. So that we can deploy multiple parse server instance. :)

gfosco commented 8 years ago

Yeah that should work very well on heroku, the separate instances don't need to share state.

hramos commented 8 years ago

I am closing this out as we're trying to cut down on the number of non-issues. This will help us focus on the issues that are actively preventing people from migrating their production apps to Parse Server.

As an alternative, I suggest opening a new discussion at Server Fault, a Q&A site dedicated to "questions about managing information technology systems in a business environment".

gateway commented 8 years ago

@hramos I do have to say nobody is really answering anything on Server Fault, its not been really helpful and while I know the parse crew is quite busy it would be nice to have some questions answered, esp when it comes to scaling or running on more than one core.

flovilmart commented 8 years ago

@gateway yes but this is also not an 'ISSUE' on parse-server, this applies to anything that is an express app backed by mongodb.