Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5150f6

Browse files
authored
Merge pull request symfonycorp#112 from tucksaun/container-xs
Document new XS container size and flexible resources allocation
2 parents 7aae9e8 + b34fbf1 commit d5150f6

File tree

5 files changed

+196
-21
lines changed

5 files changed

+196
-21
lines changed

config.rst

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,12 @@ Defines the build flavor; use ``none`` for PHP projects.
109109
Size
110110
~~~~
111111

112-
By default, SymfonyCloud allocates CPU and memory resources to each container
113-
automatically. Some services are optimized for high CPU load, some for high
114-
memory load. By default, SymfonyCloud tries to allocate the largest "fair" size
115-
possible to all services, given the available resources on the plan. That is not
116-
always optimal, however, and you can customize that behavior on any application
117-
container or on any service.
112+
Tweaks the container size. Supported values for the size key are ``AUTO`` (the
113+
default), ``XS``, ``S``, ``M``, ``L``, ``XL``, ``2XL`` and ``4XL``.
118114

119-
Legal values for the size key are ``AUTO`` (the default), ``S``, ``M``, ``L``,
120-
``XL``, ``2XL`` and ``4XL``.
121-
122-
.. note::
123-
124-
Note that in a development environment this value is ignored and always set
125-
to ``S``. It will only take effect in a production deployment (a master
126-
branch with an associated domain).
127-
128-
.. caution::
129-
130-
If the total resources requested by all apps and services is larger than
131-
what the plan size allows then a production deployment will fail with an
132-
error.
115+
Read the documentation about
116+
:doc:`resources allocations <cookbooks/resources_allocation>` for more
117+
details about the impact of this parameter.
133118

134119
.. _config-disk:
135120

cookbooks/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Cookbooks
2424
robots
2525
cloudflare
2626
symfony_no_flex
27+
resources_allocation

cookbooks/resources_allocation.rst

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
Resources Allocation
2+
====================
3+
4+
SymfonyCloud handles resource allocation in a reserved approach, rather than
5+
on-demand. This means that your project (applications plus services) are given a
6+
certain amount of resources and can use as much, or as little, of them as
7+
needed.
8+
9+
Plan Size
10+
---------
11+
12+
Your production plan size determines how much CPU and RAM are available to your
13+
entire production environment.
14+
15+
.. note::
16+
17+
The development plan has no dedicated resources allocated: the main
18+
environment is treated like a
19+
:ref:`development environment <dev-env-sizing>` and container sizes are set
20+
to ``S``.
21+
22+
You can change your project plan at anytime using the
23+
``symfony project:scale <plan>`` command.
24+
25+
Possible production plan sizes are:
26+
27+
* Standard
28+
* Medium
29+
* Large
30+
* X-Large
31+
* 2X-Large
32+
33+
Each plan comes with increasing CPU and memory compared to the previous one.
34+
Please refer to the `SymfonyCloud pricing page`_ to get the official allowance
35+
coming with each plan.
36+
37+
Container Size
38+
--------------
39+
40+
By default, SymfonyCloud allocates CPU and memory resources to each container
41+
automatically. Some services are optimized for high CPU load, some for high
42+
memory load and applications are treated as balanced. By default, SymfonyCloud
43+
tries to allocate the largest "fair" size possible to all containers, given the
44+
available resources on the plan. That is not always optimal, however, and you
45+
can customize that behavior on any application or service container.
46+
47+
.. caution::
48+
49+
If the total resources requested by all apps and services is larger than
50+
what the plan size allows then a production deployment will fail with an
51+
error.
52+
53+
.. _dev-env-sizing:
54+
.. note::
55+
56+
This value is always ignored in development environments and set to ``S``.
57+
It will only take effect in the production environment. This default
58+
development container size can be changed (paid option) if you need to.
59+
Please contact `SymfonyCloud Support`_ for more information.
60+
61+
Recommendations
62+
~~~~~~~~~~~~~~~
63+
64+
For the vast majority of applications, the default fair allocation will be the
65+
best option. In particular it will allow the application to grow as the plan
66+
size increases. If a container is set at a fixed size, however, it will not get
67+
any bigger and the extra resources might go to waste.
68+
69+
The main use-case where setting size manually is helpful is when setting
70+
particular containers to a fixed size to indicate that it really doesn't need
71+
much CPU or RAM or if its workload is fixed and doesn't need to scale much.
72+
**Static sites**, **background workers**, and other **low-need containers** can
73+
be set that way to allow more resources to go to other applications and services
74+
containers that really need them. For example, keep your main web container on
75+
the auto size and set your Symfony Messenger consumer sending emails to ``XS``.
76+
A :doc:`../services/redis` container - set to ``S`` - holding backend sessions
77+
for an application where traffic is mostly due to stateless API requests is
78+
another plausible scenario.
79+
80+
Outside of the PHP world, two additional use cases can benefit from setting
81+
these values:
82+
83+
* Shifting memory allocation from the ``memory_ratio`` to ``base_memory`` (see
84+
the `custom resources allocation`_ section) for applications with a high
85+
baseline need but a low per-request need, such as Java or Go applications.
86+
* For especially memory intensive per-process applications, setting a higher
87+
``memory_ratio`` (see the `custom resources allocation`_ section) will give
88+
those applications more head room to grow. However, be aware that doing so may
89+
draw memory away from other applications or services that need it. Try to
90+
optimize your application before throwing more resources at it.
91+
92+
In both cases you will need to do your own profiling to determine optimal values
93+
for your application.
94+
95+
Service Sizes
96+
~~~~~~~~~~~~~
97+
98+
Service sizes are set via the ``size`` property in :doc:`../services/intro`.
99+
Possible values are ``AUTO`` (the default if not set), ``S``, ``M``, ``L``,
100+
``XL``, ``2XL`` and ``4XL``.
101+
102+
Application Sizes
103+
~~~~~~~~~~~~~~~~~
104+
105+
Application (web and workers containers) sizes are set via the ``size``
106+
properties in :doc:`../config`. Possible values are ``AUTO``
107+
(the default if not set), ``XS``, ``S``, ``M``, ``L``, ``XL``, ``2XL`` and
108+
``4XL``.
109+
110+
These sizes have a fixed allocation of CPU associated with them and a default
111+
RAM one:
112+
113+
==== ==== ===========
114+
Size CPU Default RAM
115+
==== ==== ===========
116+
XS 0.25 128 MB
117+
S 0.5 192 MB
118+
M 1.0 320 MB
119+
L 2.0 576 MB
120+
XL 4.0 1088 MB
121+
2XL 8.0 2112 MB
122+
==== ==== ===========
123+
124+
.. note::
125+
126+
The smaller ``XS`` container size is only available when using custom
127+
resources allocation as describe below in the `custom resources allocation`_
128+
section.
129+
130+
Custom Resources Allocation
131+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133+
.. note::
134+
135+
The default values are appropriate for most reasonably sized scripted
136+
applications (PHP, Python, Node.js, Ruby) and so should rarely be changed.
137+
Please read carefully this section to determine if you actually need to tweak
138+
those settings.
139+
140+
Application containers have memory allocated based on a default ratio that is
141+
configurable. Two properties can be adjusted:
142+
143+
.. code-block:: yaml
144+
145+
resources:
146+
base_memory: 64 #default and minimum
147+
memory_ratio: 256 #defautl, minimum: 128
148+
149+
``base_memory`` represents a fixed amount of memory (in megabytes) allocated to
150+
the container. ``memory_ratio`` is an amount of memory allocated per CPU share.
151+
For example: an ``S`` container gets a 0.5 CPU share, with the default
152+
configuration it would get 64 + 0.5 x 256 = 192 MB of RAM.
153+
If the same container gets its size increased to an ``XL``, it would now get
154+
64 + 4 x 256 = 1088 MB of RAM.
155+
156+
Memory is expressed as two separate values to match different performance
157+
profiles depending on your application needs.
158+
159+
For instance, a PHP web application needs a relatively low base memory to start
160+
PHP-FPM, but each parallel request consumes some additional memory. It would
161+
benefit from a low ``base_memory`` and a relatively high ``memory_ratio``. That
162+
way, increasing the container size would increase the CPU share allowing more
163+
concurrent requests and its memory allocation naturally scales to match.
164+
165+
Applications in languages that have a persistent runtime, such as Java or Go,
166+
requires a high baseline memory to boot up but then each parallel request
167+
consumes relatively little memory. They would benefit from a much higher
168+
``base_memory`` value and a lower ``memory_ratio``, so that any container size
169+
has sufficient memory to start the application.
170+
171+
Background workers can also generally benefit from a higher ``base_memory``
172+
value and a lower ``memory_ratio`` if they only process one task at a time as
173+
the increase of the CPU share will speed up processing time but will not cause
174+
more tasks to be processed at once so the additional memory is not required.
175+
176+
.. _SymfonyCloud Support: https://symfony.com/cloud/support
177+
.. _SymfonyCloud pricing page: https://symfony.com/cloud/pricing

cookbooks/workers.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ specified by the ``start`` key terminates it will be restarted automatically.
5050
possible. Every data sharing needs to be done using :doc:`services
5151
</services/intro>`.
5252

53+
.. tip::
54+
55+
While worker and application containers share the same ``size`` by default,
56+
they usually benefit from being tweaked separately. Read the documentation
57+
about :doc:`resources allocations <resources_allocation>` for more
58+
details about using it.
59+
5360
Accessing a worker container
5461
----------------------------
5562

services/intro.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ generate an error if present.
9494
Size
9595
~~~~
9696

97-
This attribute has the same effect as for :ref:`application containers <config-size>`.
97+
Tweaks the service container size. Supported values for the size key are
98+
``AUTO`` (the default), ``S``, ``M``, ``L``, ``XL``, ``2XL`` and ``4XL``.
99+
100+
Read the documentation about
101+
:doc:`resources allocations <../cookbooks/resources_allocation>` for more
102+
details about the impact of this parameter.
98103

99104
.. tip::
100105

0 commit comments

Comments
 (0)