Skip to content

Commit 4e00e12

Browse files
authored
Set WEB_CONCURRENCY_SET_BY if appropriate (#2015)
The Python buildpack sets the `WEB_CONCURRENCY` env var at app boot based on the current dyno size, so long as the user hasn't specified a custom value via the app's config vars. Now, in addition to setting the `WEB_CONCURRENCY` env var, the buildpack will also set `WEB_CONCURRENCY_SET_BY=heroku/python` to allow the app, other boot time scripts, or humans more easily differentiate between user and buildpack provided `WEB_CONCURRENCY` values (plus determine which buildpack actually set it). In addition to assisting with debugging, this allows for UX improvements in other buildpacks such as the PHP buildpack, which can now check for `WEB_CONCURRENCY_SET_BY` in its boot time Apache/Nginx `heroku-php-...` scripts - helping detect the case where users have ordered the buildpacks on their app in the wrong order. (The "primary" language is supposed to be listed last, otherwise the wrong concurrency value will be used.) See also: - heroku/heroku-buildpack-php#883 - heroku/heroku-buildpack-nodejs#932 - heroku/heroku-buildpack-ruby#1700 GUS-W-20866598.
1 parent 4878b11 commit 4e00e12

File tree

8 files changed

+20
-1
lines changed

8 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- The web server concurrency calculation profile script now sets the env var `WEB_CONCURRENCY_SET_BY="heroku/python"` if `WEB_CONCURRENCY` was set automatically by the buildpack. ([#2015](https://github.com/heroku/heroku-buildpack-python/pull/2015))
56

67
## [v331] - 2026-01-11
78

spec/hatchet/ci_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
PYTHONPATH=/app
7373
PYTHONUNBUFFERED=true
7474
WEB_CONCURRENCY=5
75+
WEB_CONCURRENCY_SET_BY=heroku/python
7576
pytest .+
7677
-----> test command `./bin/print-env-vars.sh && pytest --version` completed successfully
7778
REGEX
@@ -165,6 +166,7 @@
165166
PYTHONUNBUFFERED=true
166167
VIRTUAL_ENV=/app/.heroku/python
167168
WEB_CONCURRENCY=5
169+
WEB_CONCURRENCY_SET_BY=heroku/python
168170
pytest .+
169171
-----> test command `./bin/print-env-vars.sh && pytest --version` completed successfully
170172
REGEX
@@ -258,6 +260,7 @@
258260
PYTHONPATH=/app
259261
PYTHONUNBUFFERED=true
260262
WEB_CONCURRENCY=5
263+
WEB_CONCURRENCY_SET_BY=heroku/python
261264
pytest .+
262265
-----> test command `./bin/print-env-vars.sh && pytest --version` completed successfully
263266
REGEX
@@ -345,6 +348,7 @@
345348
PYTHONPATH=/app
346349
PYTHONUNBUFFERED=true
347350
WEB_CONCURRENCY=5
351+
WEB_CONCURRENCY_SET_BY=heroku/python
348352
pytest .+
349353
-----> test command `./bin/print-env-vars.sh && pytest --version` completed successfully
350354
REGEX

spec/hatchet/pip_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
PYTHONPATH=/app
124124
PYTHONUNBUFFERED=true
125125
WEB_CONCURRENCY=2
126+
WEB_CONCURRENCY_SET_BY=heroku/python
126127
pip #{PIP_VERSION} from /app/.heroku/python/lib/python3.14/site-packages/pip (python 3.14)
127128
OUTPUT
128129
expect($CHILD_STATUS.exitstatus).to eq(0)

spec/hatchet/pipenv_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
PYTHONUNBUFFERED=true
127127
VIRTUAL_ENV=/app/.heroku/python
128128
WEB_CONCURRENCY=2
129+
WEB_CONCURRENCY_SET_BY=heroku/python
129130
pipenv, version #{PIPENV_VERSION}
130131
OUTPUT
131132
expect($CHILD_STATUS.exitstatus).to eq(0)

spec/hatchet/poetry_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
PYTHONPATH=/app
125125
PYTHONUNBUFFERED=true
126126
WEB_CONCURRENCY=2
127+
WEB_CONCURRENCY_SET_BY=heroku/python
127128
OUTPUT
128129
expect($CHILD_STATUS.exitstatus).to eq(0)
129130
end

spec/hatchet/profile_d_scripts_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
OUTPUT
4444
end
4545

46-
list_concurrency_envs_cmd = 'printenv | sort | grep -E "^(DYNO_RAM|WEB_CONCURRENCY)="'
46+
list_concurrency_envs_cmd = 'printenv | sort | grep -E "^(DYNO_RAM|WEB_CONCURRENCY.*)="'
4747

4848
# Check WEB_CONCURRENCY support when using a Standard-1X dyno.
4949
# We set the process type to `web` so that we can test the web-dyno-only log output.
@@ -53,6 +53,7 @@
5353
Python buildpack: Defaulting WEB_CONCURRENCY to 2 based on the available memory.
5454
DYNO_RAM=512
5555
WEB_CONCURRENCY=2
56+
WEB_CONCURRENCY_SET_BY=heroku/python
5657
OUTPUT
5758
end
5859

@@ -63,6 +64,7 @@
6364
Python buildpack: Defaulting WEB_CONCURRENCY to 4 based on the available memory.
6465
DYNO_RAM=1024
6566
WEB_CONCURRENCY=4
67+
WEB_CONCURRENCY_SET_BY=heroku/python
6668
OUTPUT
6769
end
6870

@@ -73,6 +75,7 @@
7375
Python buildpack: Defaulting WEB_CONCURRENCY to 5 based on the number of CPU cores.
7476
DYNO_RAM=2560
7577
WEB_CONCURRENCY=5
78+
WEB_CONCURRENCY_SET_BY=heroku/python
7679
OUTPUT
7780
end
7881

@@ -83,6 +86,7 @@
8386
Python buildpack: Defaulting WEB_CONCURRENCY to 17 based on the number of CPU cores.
8487
DYNO_RAM=14336
8588
WEB_CONCURRENCY=17
89+
WEB_CONCURRENCY_SET_BY=heroku/python
8690
OUTPUT
8791
end
8892

@@ -93,6 +97,7 @@
9397
Python buildpack: Defaulting WEB_CONCURRENCY to 9 based on the number of CPU cores.
9498
DYNO_RAM=30720
9599
WEB_CONCURRENCY=9
100+
WEB_CONCURRENCY_SET_BY=heroku/python
96101
OUTPUT
97102
end
98103

@@ -103,6 +108,7 @@
103108
Python buildpack: Defaulting WEB_CONCURRENCY to 17 based on the number of CPU cores.
104109
DYNO_RAM=63488
105110
WEB_CONCURRENCY=17
111+
WEB_CONCURRENCY_SET_BY=heroku/python
106112
OUTPUT
107113
end
108114

@@ -113,6 +119,7 @@
113119
Python buildpack: Defaulting WEB_CONCURRENCY to 33 based on the number of CPU cores.
114120
DYNO_RAM=129024
115121
WEB_CONCURRENCY=33
122+
WEB_CONCURRENCY_SET_BY=heroku/python
116123
OUTPUT
117124
end
118125

spec/hatchet/uv_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
PYTHONPATH=/app
120120
PYTHONUNBUFFERED=true
121121
WEB_CONCURRENCY=2
122+
WEB_CONCURRENCY_SET_BY=heroku/python
122123
OUTPUT
123124
expect($CHILD_STATUS.exitstatus).to eq(0)
124125
end

vendor/WEB_CONCURRENCY.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ if [[ -v WEB_CONCURRENCY ]]; then
7575
return 0
7676
fi
7777

78+
# Make it possible to differentiate between user and buildpack set WEB_CONCURRENCY values.
79+
export WEB_CONCURRENCY_SET_BY="heroku/python"
80+
7881
minimum_memory_per_process_in_mb=256
7982

8083
# Prevents WEB_CONCURRENCY being set to zero if the environment is extremely memory constrained.

0 commit comments

Comments
 (0)