4D Blog

Home Product Scalable sessions for advanced web applications

Scalable sessions for advanced web applications

January 26, 2021

Product

Nowadays, web applications are essential modern tools. As machines and processors become more and more powerful, your web applications must constantly meet performance requirements. This is why with 4D v18 R6, the 4D Web Server offers a new kind of web session: the scalable Web session.

Let’s find out more!

HDI: Scalable web sessions

Previously, you were used to the Automatic session management option on the Web page of the Structure Settings. It was convenient to keep session data alive on the server.

While 4D’s Web Server is preemptive and can take advantage of all available cores to answer web processes, each session (representing the browser from an end user) was handled through a single process, so several requests coming at once from this browser were handled sequentially, one after another

Now, scalable web sessions are able to handle several processes in preemptive mode. This means that scalable web sessions can handle several user agent requests at the same time. This greatly improves performance.

And that’s not all! These new scalable web sessions can share data between these processes.

work with scalable web sessions

Want to work with new scalable web sessions? Nothing could be simpler. Simply activate the new web settings and start your web server.

Scalable web sessions are handled through an object

Once you’ve activated the setting, you can handle the session through an object. The new Session command returns this object.

 

It’s available in any web process triggered by 4D tags, 4D actions, REST functions (ORDA Data Model Classes), and databases methods such as On Web Authentication / On Web Connection.

Thanks to this object, you can handle many aspects of your web session.

Here’s an example of what you’ll see in the debugger:

blank

share data between processes

This Session object comes with a storage property which is a shared object. You can store any data you want to share between requests coming from the user agent on the session in the storage property.

example

In this example, we have a CRM application. Each salesperson manages their own client portfolio. The database contains two linked dataclasses: Customers and SalesPersons (a salesperson has several customers).

 

blank

 

Let’s say your web server is started on your machine (IP) using an HTTPS port (port).

When the URL IP:port/4DACTION/authenticate?userId=1 is entered in a web browser by a salesperson, the authenticate method is called.

The top three customers of the salesperson are stored in the session. Here is the code of the authenticate method:


var
$indexUserId : Integer
var $userId : Integer
var $info : Object
var $userTop3 : cs.CustomersSelection
var $sales : cs.SalesPersonsEntity
ARRAY TEXT($anames; 0)
ARRAY TEXT($avalues; 0)

WEB GET VARIABLES
($anames; $avalues)
$indexUserId:=Find in array($anames; "userId")
$userId:=Num($avalues{$indexUserId})
$sales:=ds.SalesPersons.query("userId = :1"; $userId).first()
If ($sales#Null)
  Use (Session.storage)
    If (Session.storage.myTop3=Null)
     $userTop3:=$sales.customers.orderBy("totalPurchase desc").slice(0; 3)
     Session.storage.myTop3:=$userTop3
    End if
   End use

end if
WEB SEND HTTP REDIRECT("/sessionStorage.shtml")

Next, this top three are accessible by any request coming from the user agent (e.g., in an SHTML page):

<center><h3>Your top 3 customers</h3></center>
<table class="table">
  <!--#4DCODE
  $i:=0
  $myTop3:=Session.storage.myTop3
  -->
  <tr><th>Name</th><th>Total purchase</th></tr>
  <!--#4DLOOP ($i<$myTop3.length)-->
   <tr>
    <td ><!--#4DTEXT $myTop3[$i].name--></td>
    <td ><center><!--#4DTEXT $myTop3[$i].totalPurchase--></center></td>
   </tr>
   <!--#4DEVAL $i:=$i+1-->
  <!--#4DENDLOOP-->
</table>

And here is the result:

blank

upcoming actions with the session

We’re working on an accurate privileges management for the future. So that you will be able to grant access + operations on data according to privileges.

For now, you can put user’s information in the session thanks to the setPrivileges() function. This function will be enhanced to handle more actions for privileges in a future release. 

example

var $indexUserId : Integer
var $userId : Integer
var $sales : cs.SalesPersonsEntity
var $info : Object
ARRAY TEXT($anames; 0)
ARRAY TEXT($avalues; 0)
WEB GET VARIABLES($anames; $avalues)
$indexUserId:=Find in array($anames; "userId")
$userId:=Num($avalues{$indexUserId})
$sales:=ds.SalesPersons.query("userId = :1"; $userId).first()
$info:=New object()
$info.userName:=$sales.firstname+" "+$sales.lastname
Session.setPrivileges($info)

So you can customize your web pages by adding something like this:

<center>
<h3>
Hello <!--#4DEVAL Choose(Session.userName # ""; Session.userName; "nobody")-->
</h3>
</center> 

Here is the result:

blank

As you may have noticed in the debugger screenshot, scalable web sessions close (timeout) after 60 minutes of inactivity (i.e., no requests solicits the session).

Download the HDI above to discover more and join the discussion on the 4D forum!

 

 

Discuss

Tags Performance, Preemptive, Programming, Scalable, Session, Speed, v18 R6, v19, Web, Web session

Latest related posts

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

  • April 28, 2025

    Unlock the Power of AI with 4D AIKit: Automate, Create, and Innovate

  • April 25, 2025

    Formulas in Label Wizard

Avatar
Marie-Sophie Landrieu-Yvert
• Product Owner • Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor Workbook

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor Workbook
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy