KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How does 4D v13 optimize static requests?
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: April 12, 2013

In order for any application to scale vertically, preemptive execution is necessary. For the past several releases 4D has been constantly improving the architecture so that, when possible, 4D can scale to take advantage of all the hardware resources. The 4D language remains cooperative, so it is not possible optimize 4D code execution in this matter yet there are still improvements that can be made.

4D v13 introduces preemptive request handling to 4D's Web server. In previous versions the 4D Web server was completely cooperative, even for static requests, so only a single CPU/core could be used to handle all Web traffic. In 4D v13 all static content benefits from preemptive execution. It is still not possible for dynamic Web requests to be handled preemptively (because of the aforementioned limitation of the 4D language) but there are still significant performance gains to be made from this change.

Here is how 4D handles a "hybrid" design that allows cooperative dynamic Web requests to coexist with preemptive static requests.

When a request reaches the server it is handled by a pool of preemptive threads.



The preemptive thread parses the request to see if it is static or dynamic. If it is static, the content is simply served preemptively:



If the request is dynamic, the preemptive thread hands execution off to a cooperative 4D process and suspends itself waiting for the execution to complete:



Once the 4D code has completed execution, the preemptive thread wakes up and sends the result.