April 17, 2015

Managing Heroku Dynos to Optimize Concurrency and Memory Use

Written by Gen

keyword icon Heroku

As your app's characteristics change, you need to ensure you're using the optimal number and types of dynos. You also have to monitor Heroku's load balancing and memory use to verify that your app is scaling to best effect.

The two primary reasons developers choose to host their apps on Heroku are the service's performance and scalability right out of the box. This is particularly true when processing web dynos, which are any dynos that run the 'web' process type and receive HTTP and HTTPS traffic.

The random selection algorithm that handles HTTP request load balancing accommodates multiple simultaneous connections. It also responds to time outs automatically, as the Heroku Dev Center explains in the article How Heroku Works.

The Dev Center article on scaling dyno formations steps through use of the 'ps:scale' command to set the concurrency level of web and worker process types by adjusting the number dynos running each type. The number can be either an absolute number or an increment of total dynos running. Scaling to '0' stops that particular process type from running.

heroku ps: scale web=2, scaling dynos,

The 'ps:scale' command adjusts the number and type of dynos running: for a single process type (first screen), for both types (second), as an increment (third), and to stop the process type (fourth). Source: Heroku Dev Center

To maximize memory and CPU use, scale the dynos vertically. For example, scale up to two 2X dynos, down to one 2X dyno, and back to two 1X dynos, as shown in the screens below.

heroku ps: scale, scaling dynos

Scale dynos vertically: to two 2X dynos (first screen), to one 2X dyno (second), and to two 1X dynos (third). Source: Heroku Dev Center

Digging deeper into Heroku's routing mesh, memory optimization

The ability to scale dynos without having to deal with load balancing is one of Heroku's most useful tricks. The load balancer passes incoming requests to routers that locate the app's web dynos and forward each HTTP request to one dyno. Each router's per-app request queue holds the overflow once the router exceeds its limit on active requests, which for Cedar apps is 50 requests per dyno.

The routers buffer the header section of all the requests they receive. When a dyno encounters a slow client, it has the header before the body is received. You can use information in the header to determine how long you want to wait before closing the connection at the dyno by dropping the request, as explained in a Heroku Dev Center article.

The three steps Heroku recommends for optimizing memory are to use a concurrent web server, apply instrumentation to determine how well the app is handling the load, and monitor app performance, tweaking as necessary as conditions change. The particulars of the tweaking depend on the language, web framework, and the application itself.

For example, a web server for a Ruby app may need to fork multiple copies of the app to use all available RAM, while a Java app is served adequately by a parameter to the JVM to allocate a larger heap. Heroku Labs' log-runtime-metrics feature provides a clear view into the load and memory use of running dynos, including memory use, swap use, and load average. This and other information is inserted into the app's log stream.

source=web/1 dyno=heroku

The log-runtime-metrics function adds load and memory use information to the app's log stream. Source: Heroku Dev Center

Monitoring the performance of your apps, databases, IT operations, and business services is simplified and centralized in the Happy Apps application-management service. Happy Apps lets you set up rules so you are alerted via SMS and email whenever incidents or specific events occur. You can group and monitor multiple apps, databases, web servers, and app servers. In addition to an overall status, you can view the status of each individual group member.

Happy Apps is the only app-management service to support SSH and agent-based connectivity to all your apps on public, private, and hybrid clouds. The service provides dependency maps for determining the impact your IT systems will have on other apps. All checks performed on your apps are collected in easy-to-read reports that can be analyzed to identify repeating patterns and performance glitches over time. Visit the Happy Apps site to sign up for a free trial.

comment icon Comments

* Required

Oxigipgab says:
December 14, 2020 11:18 PM

achat de cialis doctissimo jaique <a href=https://bansocialism.com/>buying cialis online</a> ribrenes Priligy Istruzioni

Oxigipgab says:
December 16, 2020 11:03 AM

Amoxicillin And Prednisolone jaique <a href=https://bansocialism.com/>daily cialis online</a> ribrenes Ou Trouver Du Cialis A Paris

sapApartith says:
January 25, 2021 11:04 AM

cannabis oil https://cbdgummieswkj.com/ - cbd oil online for sale cbd gummies store buy cbd oil

Tevaaccincams says:
March 10, 2021 03:01 AM

https://casinoslotspc.com/ online casino slots world class casino slots <a href="https://onlinecasinogamesww.com/ ">vegas slots online </a> online casino

how long do the effects of vardenafil last says:
April 12, 2021 03:16 AM

teva pharms vardenafil https://vegavardenafil.com/ staxyn (vardenafil)

zithromax online canada says:
April 12, 2021 04:14 PM

zithromax directions https://zithromaxes.com/ zithromax otc

erectile dysfunction treatment says:
April 12, 2021 08:48 PM

best erectile medicine https://canadaerectiledysfunctionpills.com/ top erectile urologists in san francisco

alprostadil comes from says:
April 18, 2021 07:45 PM

alprostadil suppository demonstration video https://alprostadildrugs.com/ muse alprostadil suppository

buy generic cialis, canadian says:
April 22, 2021 03:34 AM

buy cialis online canadian https://canadacialisstore.com/ canadian viagra cialis

canadian pills pharmacy says:
April 22, 2021 09:51 AM

canadian customs pills vitamins https://canadapillstorex.com/ canadian generic pills

tadalafil 40 mg from india says:
April 25, 2021 06:39 PM

tadalafil dosage https://elitadalafill.com/ tadalafil daily use

plaquenil sulfate says:
April 27, 2021 12:11 AM

erectile improvement https://plaquenilx.com/ can erectile dysfunction be psychological

dapoxetine says:
April 27, 2021 10:31 PM

priligy without a doctor prescription <a href="https://priligydapoxetinex.com/#">priligy online</a>

sildenafil buy says:
April 28, 2021 09:35 PM

sildenafil online nz https://eunicesildenafilcitrate.com/ sildenafil brand name in india

canadian diet pills says:
May 1, 2021 09:25 AM

canadian pills pharmacy https://canadapillstorex.com/ average perscription pills taken by 65 year old canadian?

canadian generic cialis safe says:
May 2, 2021 02:44 AM

cialis viagra combination canadian pharmacy https://canadacialisstore.com/ buying canadian cialis

aralen hydrochloride says:
May 4, 2021 10:44 PM

hloroquine https://chloroquineorigin.com/ chloroquine side effects

Oxigipgab says:
May 5, 2021 07:10 AM

<a href=https://vsdoxycyclinev.com/>doxycline hyclate 100mg purchase

Oxigipgab says:
May 7, 2021 12:13 AM

<a href=http://gcialisk.com/>buy cialis online without prescription