The 4D Web Server allows you to take full advantage of multi-core computers by using preemptive web processes in your compiled applications. You can configure your web-related code, including 4D tags and web database methods, to run simultaneously on as many cores as possible.
For in-depth information on preemptive process in 4D, please refer to the Preemptive 4D processes section in the Language Reference.
Availability of preemptive mode for web processes
The use of preemptive mode for web processes is only available in the following contexts:
use of 4D Server or 4D local mode (4D in remote mode does not support preemptive mode)
use of a compiled database (except on 4D Server when sessions are enabled)
Use preemptive processes database setting checked (see below)
all web-related database methods and project methods are confirmed thread-safe by 4D Compiler
If any requirement is missing, the web server will use cooperative processes.
Enabling the preemptive mode for the web server
To enable the preemptive mode for your application's web server code, you must check the Use preemptive processes option on the "Web/Options (I)" page of the Database Settings dialog box:
When this option is checked, the 4D compiler will automatically evaluate the thread-safety property of each piece of web-related code (see below) and return errors in case of incompatibility.
This option does not apply to web service processes (server or client). Preemptive mode is supported by web service processes at method level: you just have to select "Can be run in preemptive processes" property for published SOAP server methods (see Publishing a Web Service with 4D) or proxy client methods (see Subscribing to a Web Service in 4D) and make sure they are confirmed thread-safe by the compiler.
Writing thread-safe web server code
All 4D code executed by the web server must be thread-safe if you want your web processes to be run in preemptive mode. When the Use preemptive processes option is checked in the Settings dialog box, the following parts of the application will be automatically evaluated by the 4D compiler:
All web-related database methods:
compiler_webproject method (regardless of its actual "Execution mode" property);
Basically any code processed by the
PROCESS 4D TAGScommand in the web context, for example through .shtml pages.
Any project method with the "Available through 4D tags and URLS (
4DACTION, etc.)" attribute
Triggers for tables with "Expose as REST resource" attribute
Project methods available through REST ("REST Server" property checked)
For each of these methods and code parts, the compiler will check if the thread-safety rules are respected, and will return errors in case of issues. For more information about thread-safety rules, please refer to the Writing a thread-safe method paragraph in the Processes chapter.
Thread-safety of 4D web code
Most of the web-related 4D commands and functions, database methods and URLs are thread-safe and can be used in preemptive mode.
4D commands and database methods
All 4D web-related commands are thread-safe, i.e.:
- all commands from the Web Server theme,
- all commands from the HTTP Client theme.
The web-related database methods are thread-safe and can be used in preemptive mode (see below):
On Web Authentication,
On Web Connection,
On REST Authentication...).
Of course, the code executed by these methods must also be thread-safe.
URLs del servidor web
The following 4D Web Server URLs are thread-safe and can be used in preemptive mode:
- 4daction/ (the called project method must also be thread-safe)
- 4dcgi/ (the called database methods must also be thread-safe)
- 4dimgfield/ (generated by
PROCESS 4D TAGSfor web request on picture fields)
- 4dimg/ (generated by
PROCESS 4D TAGSfor web request on picture variables)
Preemptive web process icon
Both the Runtime Explorer and the 4D Server administration window display a specific icon for preemptive web processes:
|Preemptive web method|