Hosting the workbench¶
The workbench is one Python process (FastAPI on uvicorn) plus a pool of solver processes it starts itself. It serves the page, its scripts and its fonts from the package and makes no request to any other host, so it only needs a reverse proxy in front for TLS.
This page is a template. The commands are the standard ones for these tools: check them on your server.
Install¶
python -m venv /opt/openairbearing
/opt/openairbearing/bin/pip install "openairbearing[web]"
Run¶
For a site open to anyone, start it with the public limits:
/opt/openairbearing/bin/python -m openairbearing.ui --public --host 127.0.0.1 --port 8050
--public limits what one request may cost and, unless told otherwise,
uses at most 4 solver processes. Without it (a workbench at one’s own desk,
or a trusted server) the limits on size, work and time are dropped; the
number of solves of a study stays capped. The number of solves alone does
not bound the cost: a solve on the largest mesh the form allows takes far
longer, and far more memory, than one on a default mesh, and the volume
restrictor model is much slower than the column model on the same mesh, the
more so the larger the mesh. So the mesh and the product of solves and mesh
size are limited too. Each setting can be given in the environment, and some
on the command line:
Setting |
Flag |
Environment |
Local default |
|
|---|---|---|---|---|
Film solves per study |
|
|
2000 |
400 |
Nodes of a film mesh |
|
no limit |
40 000 |
|
The same, volume restrictor model |
|
no limit |
5 000 |
|
Nodes of a porous body (monolithic thrust bushing) |
|
no limit |
30 000 |
|
Solves × nodes of a study |
|
no limit |
8 000 000 |
|
Seconds one study may run |
|
no limit |
300 |
|
Seconds for a field, mesh or free flow |
|
no limit |
60 |
|
Solver processes |
|
|
all cores but one |
the same, up to 4 unless set; at least 1 |
Stiffness counts its extra solves (two per position coordinate at every
point), and a solve with the volume model counts many times in solves × nodes
(VOLUME_WEIGHT in openairbearing/study.py, which says how it was measured).
With the column restrictor model, 400 points of any default bearing run
(fewer with stiffness). With the volume model the node limit refuses the
default journal, annular pad and thrust bushing outright, and the other
default bearings get far fewer points. A request over a limit is refused
with the reason before anything is solved.
A study stops when it is cancelled, when its time is up, and when nobody has
asked for its progress for two and a half minutes: the page withdraws when
it is closed, and a browser that vanished stops asking. Stopping ends the
solver processes, since a solve that has started cannot be interrupted
otherwise; new ones start with the next study. At most 8 studies wait in
the queue. Pressure fields, meshes and free flows are computed in one
process of their own, so they are answered while a study runs; 2 may wait
at once, and further requests are answered with “try again”. A request body
over 1 MB is refused, and the interactive API pages of the framework
(/docs, /redoc) are switched off.
Run exactly one server process: jobs and finished results are kept in its memory, so several processes behind a load balancer would not see each other’s jobs. A restart drops running studies; visitors just run them again.
An ASGI server can also load the app itself:
uvicorn --factory openairbearing.ui.server:create_public_app --host 127.0.0.1 --port 8050
systemd unit¶
[Unit]
Description=openairbearing workbench
After=network.target
[Service]
User=openairbearing
ExecStart=/opt/openairbearing/bin/python -m openairbearing.ui --public --host 127.0.0.1 --port 8050
Restart=on-failure
NoNewPrivileges=true
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Reverse proxy¶
Any proxy that forwards to 127.0.0.1:8050 works. With Caddy, which also
obtains the certificate:
example.com {
request_body {
max_size 1MB
}
reverse_proxy 127.0.0.1:8050
}
With nginx, inside the server block for the site:
location / {
proxy_pass http://127.0.0.1:8050;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 1m;
}
The page polls for the progress of a study with ordinary short requests, so
no websocket is needed. A pressure field, a mesh or a free flow is one
request, which may take as long as its time limit and as long again while it
waits behind another: set the read timeout of the proxy above twice
OAB_FIELD_SECONDS. A request-rate limit in the proxy is a sensible extra
guard on a public site.
What visitors’ browsers store¶
The page keeps the last study and a random browser id in the browser’s local storage. The id only tells the server which browser asked for a study, so that cancelling does not stop a study someone else is waiting for. Nothing is sent anywhere but to this server, and the server keeps no log of studies beyond its in-memory result cache.