Why does MATLAB Web App Server use so much memory per worker?

16 views (last 30 days)
I am running MATLAB Web App Server on a Windows machine that also handles other applications and license managers. When Web App Server is not running, the Windows server already uses about 50-55% of its RAM capacity. These other applications could hang or crash if they cannot access enough RAM, which would be unacceptable.
When I run MATLAB Web App Server, the webapps processes use about 700 MB per worker (ctfxlauncher.exe). I want to run 3 apps simultaneously, so MATLAB Web App Server uses uses 2 GB+ of RAM.
Is there a way to reduce the memory usage of MATLAB Web App Server workers?

Accepted Answer

MathWorks Support Team
MathWorks Support Team about 16 hours ago
As per the product requirements for MATLAB Web App Server, you should expect to allocate approximately 1 GB of RAM per worker session. However, the exact memory usage of each worker depends on a number of factors.
The most significant reasons for MATLAB Web App Server's memory use per worker are the following:
  1. Starting the Java Virtual Machine (JVM) and running Java code during startup uses a lot of memory. This could account for more than 300MB.
  2. Number of products loaded for the worker. For any MATLAB process, the more products installed on top of base MATLAB, the more memory the process will consume as it starts up. By default, MATLAB Runtime includes all products and toolboxes.
  3. During worker startup, the MATLAB process needs to load many shared libraries and cached content, including any libraries required by the prewarming CTF. This feature comes with some upfront memory overhead.
After startup, the memory use of any particular worker is largely dependent on the specific app it is running. Most standard apps will use less than 1GB RAM while running, but apps that use more memory-intensive functionality may require more. You can get a relative estimate of an app's memory requirements by checking memory usage when running the app in MATLAB or as a standalone app, but note that this may not be exactly the same as when run as a web app. 
There are several options for limiting or reducing the active memory usage for MATLAB Web App Server: 
  • Reduce prewarming. At startup, the MATLAB Web App Server prewarms several workers for each runtime configured on the server. This helps to reduce startup time for apps, but these prewarmed workers consume additional memory on top of running sessions. To customize the number of prewarmed workers for your server, see Why is MATLAB Web App Server's memory consumption high even when no apps are running?
  • Run workers with -nojvm. If the JVM is not required for your apps, you can configure workers to run without the JVM in R2024a or later by editing the WorkerRuntimeOptions tag in webapps.config to match the following: 
    <WorkerRuntimeOptions>-nojvm -webui<WorkerRuntimeOptions/>
  • Use containerized workers. On Linux, if you are using the product version of MATLAB Web App Server with containerization, you can use the webapps-containers command to limit the maximum amount of memory (RAM) a worker can use: 
    sudo ./webapps-containers.sh config set memory "1g"
Note that the 1GB RAM per worker recommendation is implemented by setting the maximum number of sessions (maximum_sessions) using webapps-config. This does not "reserve" a certain amount of memory for a given worker, nor does it limit the amount of memory an individual worker can use; it only limits the maximum amount of worker sessions that may run at one time. If your apps typically require more than 1GB RAM to run, you should consider reducing the maximum sessions to ensure there is enough memory available to support each running app session.

More Answers (0)

Categories

Find more on MATLAB Web App Server in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!