Updates
- 17.03.2015 added information that security session management has to be activated
- 11.10.2019 changed layout after the automatic conversion so that screen shots are again visible
Introduction
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.
Prerequisites
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 .
Important:
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:
Activating HTTP Security Session Management on AS ABAP - User Authentication and Single Sign-On - SA...
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
Steps |
Result |
---|
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.
super->define( ).
model->set_soft_state_enabled( abap_true ).
endmethod. |
Implementation steps in the data provider class
Test the service in the browser
Steps |
---|
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.
Please note:
If you have configured a small time window (for example 10 seconds) you will probably have to wait longer since there is an additional latency. If you are too impatient and click on refresh to fast the wait time starts again from zero. |
|
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.
Steps |
---|
Start a performance trace using /IWFND/TRACES.
Perform several requests with $count having soft state enabled |
We can see that the initial request takes 16 milliseconds in the backend (GW framework overhead + Application Data Provider response time).
For every subsequent request the Application Data Provider Response time is zero and the GW framework overhead is reduced to 5 mill seconds. |
|
Deactivate soft state and perform again several requests with $count |
The result now is that subsequent requests have the same response time.
The response time is the same that we got for the first initial request when soft state was enabled. |
|