Getting the Most Out of Cloud Servers Without Additional Scripting
Want to squeeze every last drop of utility from the cloud without resorting to work-intensive scripts? Here are a few ways to do it.
Join the DZone community and get the full member experience.Join For Free
we all want to get the most out of cloud servers. we want to find ways to make our spend stretch far when it comes to our cloud infrastructure. we also want to see all vcpu cores on our cloud instances fully utilized. let's look at some strategies for how to do this, and how cloud 66 can help you get the most out of your monthly cloud spend without writing and maintaining any complex automation scripts.
strategy #1: make it easy to scale your app
your approach to deploying applications can have an impact on how easy it is (or isn't) to scale your app. while you can deploy your application on the same server as your database in the early days of your application, don't stick with this strategy as your app experiences more traffic. your database requires memory and cpu to service the queries you send to it, negatively impacting the overall performance of your application. it will also create a single point of failure (spof), as you'll be relying on a single server for everything in your stack.
instead, separate your database from your application using a service such as amazon rds, a third-party database-as-a-service, or using the cloud 66 managed database service. this will allow your web app to use as much of the available cpu as possible. it will also allow you to scale the number of app server instances up or down based on anticipated traffic. plus, you'll offload the management of your database to a third-party, freeing you to focus on app development and customer support.
strategy #2: push everything to the background
the performance of your application depends on its ability to accept an incoming http request, process that request, and send back a response as fast as possible. anything not contributing to this flow is extra work that negatively impacts performance, requiring more servers when under peak load. by moving as much work as possible to be processed in the background, you free your web app to process critical request/response flows without wasting cpu and memory doing work that can be pushed until later.
a common approach to offloading work to the background is to use a distributed messaging approach, as detailed in our realscale article . solutions such as sidekiq are commonly used to make this approach easy for rails developers. simply write a background worker that handles the processing, then deploy on one or more worker processes to handle these background tasks.
cloud 66 makes this easy by allowing applications to define a procfile for both the web app process, along with background processes deployed on the same server. your server will now handle web app requests, along with background processes on the same server.
for background work that is cpu and/or memory intensive, you also have the option of deploying dedicated process servers rather than sharing the same web app servers. by separating your web app and background processes to different servers, you can select different instance sizes to fit your stack needs. e.g. larger instances for your app servers, smaller instances for background processes.
strategy #3: make use of all your vcpus
you may not realize it, but not all web frameworks use your cpus in the same way. for example, when deploying a rails app, you have several rack server options. if you just use the default, you may not use all of the vcpus available to you from your cloud provider. this results in one or just a few of the available vcpus from being used.
choose the right rack server to use all of your vcpus by launching multiple processes. a common recommendation is to use unicorn with rack . unicorn forks multiple processes, allowing each process to use one of the available vcpus to process an incoming request. this helps to maximize the use of each app server, rather than deploying multiple servers that use only 25% of the available vcpus.
strategy #4: select the right strategy to deploy at scale
once you start to scale your application, your deployment process will start to take longer as each server is upgraded. this requires that you modify your deployment strategy to handle additional servers. one option to speed up deployment is to use a parallel deployment strategy. by using this strategy, deployments occur on multiple servers at once in a serial fashion, rather than on a server-by-server basis. this does, however, have an impact on how you migrate your database, so be sure to read our help page on taking advantage of parallel deployments before selecting this option.
strategy #5: use redeployment hooks to avoid deploy scripting
scripting your deployment process often requires a deep understanding of server deployment processes, such as those outlined above, as well as understanding how to use tools such as capistrano, chef, puppet, or ansible. all this scripting work takes away valuable time from building and supporting your application. plus, your team must keep up with the latest changes, often during a critical deployment time when your scripts break due to changes with deployment tools. we outlined many of these issues in a recent article, "7 obstacles to overcome when deploying ruby on rails to production" .
by using redeployment hooks , you can deploy your application to one or more servers easily. using redeployment hooks, all of this scripting can be eliminated by triggering a new deploy every time code has been merged into a specific branch in your git repository (e.g. master). you can even connect the cloud 66 deployment process to an automated test solution, such as travisci , to ensure that only tested code is deployed into production.
Published at DZone with permission of James Higginbotham, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.