Skip to content

Commit

Permalink
Add flag "OPTIMIZE_MEMORY=true" to turn max_old_space_size on
Browse files Browse the repository at this point in the history
[#143873083]

Signed-off-by: Dave Goddard <dave@goddard.id.au>
  • Loading branch information
nikitarathi23 authored and cf-buildpacks-eng committed May 19, 2017
1 parent 5962f63 commit fd5c9ee
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 49 deletions.
14 changes: 9 additions & 5 deletions bin/release
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env bash
# bin/release <build-dir>

cat << EOF
addons: []
default_process_types:
web: npm start --max-old-space-size=$(( $(jq -r '.limits.mem' <<<"$VCAP_APPLICATION") * 75 / 100 )) $NPM_CLI_OPTIONS
EOF

echo 'addons: []'
echo 'default_process_types:'

if [[ "${OPTIMIZE_MEMORY:-}" = "true" ]]; then
echo ' web: npm start --optimize_for_size --always_compact --max_old_space_size=$(( $(jq -r '.limits.mem' <<<"$VCAP_APPLICATION") * 75 / 100 ))'
else
echo ' web: npm start'
fi
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions cf_spec/fixtures/simple_app/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
memory: 350MB
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node_web_app",
"name": "simple_app",
"version": "0.0.0",
"description": "hello, world",
"main": "server.js",
Expand All @@ -8,12 +8,6 @@
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"logfmt": "~1.1.2",
"express": "~4.0.0"
},
"engines" : {
},
"repository" :
{
"type" : "git",
Expand Down
16 changes: 16 additions & 0 deletions cf_spec/fixtures/simple_app/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const http = require('http')
const port = process.env.PORT || 8080

const requestHandler = (request, response) => {
response.end(`MaxOldSpace: ${process.env.npm_config_max_old_space_size}`)
}

const server = http.createServer(requestHandler)

server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}

console.log(`server is listening on ${port}`)
})
1 change: 0 additions & 1 deletion cf_spec/fixtures/without_procfile/.npmrc

This file was deleted.

4 changes: 0 additions & 4 deletions cf_spec/fixtures/without_procfile/package.sh

This file was deleted.

1 change: 0 additions & 1 deletion cf_spec/fixtures/without_procfile/resolve

This file was deleted.

18 changes: 0 additions & 18 deletions cf_spec/fixtures/without_procfile/server.js

This file was deleted.

26 changes: 13 additions & 13 deletions cf_spec/integration/deploy_a_node_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'open3'

describe 'CF NodeJS Buildpack' do
subject(:app) { Machete.deploy_app(app_name) }
subject(:app) { Machete.deploy_app(app_name, env: app_env) }
let(:app_env) { {} }
let(:browser) { Machete::Browser.new(app) }
let(:buildpack_dir) { File.join(File.dirname(__FILE__), '..', '..') }
let(:version_file) { File.join(buildpack_dir, 'VERSION') }
Expand Down Expand Up @@ -82,33 +83,32 @@
context 'with an unsupported, but released, nodejs version' do
let(:app_name) { 'unsupported_node_version' }

it 'displays a nice error messages and gracefully fails' do
it 'displhttps://github.com/cloudfoundry-samples/pong_matcher_rails/pull/3ays a nice error messages and gracefully fails' do
expect(app).to_not be_running
expect(app).to have_logged 'Downloading and installing node 4.1.1'
expect(app).to_not have_logged 'Downloaded ['
expect(app).to have_logged /DEPENDENCY MISSING IN MANIFEST: node 4\.1\.1.*-----> Build failed/m
end
end

context 'with no Procfile and no NPM_CLI_OPTIONS env var' do
let (:app_name) { 'without_procfile' }
context 'with no Procfile and OPTIMIZE_MEMORY=true' do
let (:app_name) { 'simple_app' }
let (:app_env) { { OPTIMIZE_MEMORY: true } }

it 'is running with autosized max_old_space_size' do
expect(app).to be_running
expect(app).to have_logged("--max_old_space_size=768")
browser.visit_path('/')
expect(browser).to have_body('MaxOldSpace: 262') # 350 * 75%
end
end

context 'with no Procfile and with NPM_CLI_OPTIONS env var' do
let (:app_name) { 'without_procfile' }
context 'with no Procfile and OPTIMIZE_MEMORY is unset' do
let (:app_name) { 'simple_app' }

subject(:app) do
Machete.deploy_app(app_name, env: {'NPM_CLI_OPTIONS' => '--trace-sync-io'})
end

it 'is running with autosized max_old_space_size and appended NPM_CLI_OPTIONS' do
it 'does not run with autosized max_old_space_size' do
expect(app).to be_running
expect(app).to have_logged("--max_old_space_size=768 --trace-sync-io")
browser.visit_path('/')
expect(browser).to have_body('MaxOldSpace: undefined')
end
end

Expand Down

0 comments on commit fd5c9ee

Please sign in to comment.