learning-website-nextjs1-2 Exercise 3: One App or Many? Measure Before Deciding
===================================================================================
Two shapes now exist side by side, so they can be compared on this machine instead of by opinion.
Many apps (Chapter 1) One app (this chapter)
build one build per app: 18.6 s for 3 one build: 11.2 s (9 pages)
(11.4 s for one from cold)
memory, running 3 processes, 268 MB (about 89 MB 1 process, 84 MB
each, so about 700 MB for 8: an
extrapolation)
a failing site the other sites keep running every site is down together
a change to ONE site rebuild and redeploy that app rebuild and redeploy everything
a change to shared rebuild every app rebuild the one app
code
deploying eight things to start, monitor one thing; but Apache must pass the
and give a port original Host header on (below)
routing Apache sends each host to a port Apache sends every host to one port;
(the app never looks at the host) the proxy file picks the site
Memory was measured as the Windows working set of the node processes after each server had answered a
request: one app 84 MB; three apps 268 MB. That is an idle, freshly started machine, not a loaded server,
and Debian will differ. The build times are one run each. The comparison is therefore a guide to the
SHAPE of the cost, not a benchmark.
The Apache part, written but NOT run (no Apache here):
# many apps: one ProxyPass per host
ServerName languages.osztromok.com
ProxyPass / http://127.0.0.1:3001/
# one app: every host goes to port 3010, and Apache MUST keep the original Host header
ServerName languages.osztromok.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3010/
Without ProxyPreserveHost On, Apache would send Host: 127.0.0.1:3010 to the app, which is "not ours", so
every request would be a 404. That is the one thing that can silently break the one-app shape, and it
cannot be seen in development.
How to choose (an opinion, not a measurement): the many-apps shape costs memory and operations (eight
processes) and buys isolation; the one-app shape is cheaper and simpler, and a bug in any site can take
all of them down. With eight sites on one small server, one app is the lighter choice; with sites that
change at different speeds or may move to different servers, separate apps are safer. This course keeps
the separate apps from Chapter 1 and uses the one-app version as a tested alternative.
WHY THIS WORKS AS AN ANSWER
---------------------------
It puts numbers beside each claim, says which numbers are single runs on a development machine, and names
the one setting that breaks the cheaper shape.