Hi, I have a situation where we calls DAO in servlet filter for user authorization. During the load test we realizes that this things become bottleneck and spawn multiple threads results in crashing server environment. But when we remove this call from filter and do the same thing after chain.doFilter() method, like in Action class it does not create same problem. What I want to know, is there a difference in handling database calls in Filter verses in POJO?
A filter will be invoked for each request to the mapping for which it is configured. Why on earth would you need to authenticate the user on each and every request? Once the user is authenticated, simply indicate as such in the session and stop beating the DB to death.
I wish it was just authentication but this is about authorization in the application. In our application user deals with case ids where he has access to limited number of cases. So, whenever he makes request with some case id, we check if he is authorized to play with that case_id in the filter itself which involves DB call. My problem is it crashes server when i do this activity in the filter not anywhere else. So, wondering if web container handles it different way.
No, code is code. Do you observe a greater number of DB calls when there are problems than when there are not?
Joined: Aug 07, 2008
Number of db calls are same in both the cases. Actually, I am running load test on the application with some 500 vusers. DB queries are optimized and has no load on db. When I have this filter code which makes queries for authorization check, after a while everything slows down and throws a websphere core dump showing thread contention in websphere. DB connection pool is quite enough to handle required connections by this load test. When I move this db calls from filter to action class layer I don't see this issue. So, again wondering why this happens only when in servlet filter.
It should make no difference whether the code runs as a filter invocation or in an action class, so I cannot account for you observations. I'm moving this over to the websphere forum for those more familiar with websphere to comment.