- 17.03.2015 added information that security session management has to be activated
The so-called “soft state” mode enables the SAP NetWeaver Gateway runtime to process several requests in one ABAP application server session, similar to stateful behavior. The only difference is the behavior of the application server after the session times out: Instead of breaking the request processing with a time-out exception the server creates a new session and processes the request as usual. For the consumer the change of the application server sessions is transparent and no data is lost on the client session.
The session that is held by the ICF framework results in session held in the backend system via RFC where the data provider class can cache data in member variables. The Data Provider Cache is highlighted in green in the following figure.
The soft state mode should be used for applications built on legacy functionality in the backend, especially when the functionality includes initial loading/caching of big amounts of data for a single request. A typical example would be a price calculation.
By using soft state, the resources/functionality which has been loaded during the initial load can be reused for the subsequent requests of the service. Thus, the main benefit of soft state is a considerable performance optimization of an OData service.
You have created a sample OData service using the Service Builder as described in my SCN document How to Develop a Gateway Service using Code based Implementation .
In order to use soft state it is mandatory that HTTP Security Session Management on AS ABAP has been activated. Security session management can be managed using transaction SICF_SESSIONS as described in the SAP Online Help:
Even if secúrity session management is not being activated a service currently is shown as active for soft state but does not work as supposed.
Overview – Implementation steps to activate Softstate for your service
- Redefine the DEFINE method of the model provider extension call
- Create an instance attribute MV_IS_SOFTSTATE for the DPC_EXT class that stores the status whether soft state is activated
- Redefine the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_START to set this variable
Implementation steps in the model provider class
|1. Start maintaining the model provider extension class ZCL_ZGW_PRODUCT_MPC_EXT|
|2. Redefine the DEFINE method of the MPC_EXT class||method DEFINE.
model->set_soft_state_enabled( abap_true ).
Implementation steps in the data provider class
Test the service in the browser
|Call your service via the browser.||http://<server>:<port>/sap/opu/odata/sap/ZGW_PRODUCT_SRV/ProductSet/$count|
|When refreshing the URL you will notice that the counter will start to count the number of calls.|
|Wait for 20 seconds …|
When you wait for a period longer than the one configured as a session timeout in SICF the counter starts with 1 again.
Comparison of response times
The behaviour when using soft state or not can nicely be checked using the performance trace. This can be started using transaction /IWFND/TRACES.