Search code examples
jsfprimefaceswebsphereviewstatemyfaces

Why client state saving works faster for single user?


I'm using PrimeFaces 3.4 with MyFaces 2.0.7 on WebSphere 7. I've noticed that saving state to client result in about 2 times faster request processing than server saving state. When client saving state is activated, request takes from 150 to 350m. With server state saving it's from 300 to 600ms. ViewState in POST has about 200kb.

So the cost payed form the speed is the data transfer. Fortunatelly it's intranet application only.

But what wonders me is, how can it be implemented, that sending state in http requests is faster than restoring it from session? I understand that while having a few thousand concurrent users sessions would be serialized to disk, so restoring something from session would be disk-bound operation, while from client only client-bound.

But I'm the only user during the tests. Is such speed difference expected behaviour, or this is wrong configuration of the server?


Solution

  • MyFaces by default are serializing ViewState in session. So even if the sessions itself are not serialized, the serialization overhead was also added, and additionally the storage of value in session also costs some time.

    The solution was to change default behaviour via param in web.xml:

    <context-param>
        <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
        <param-value>false</param-value>
    </context-param>    
    

    Now I have times from 125 to 250ms, with storing ViewState on server. So it's faster.