• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Servlet & Filter

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HighLevel:
I have 3 filters configured for a servlet.I have to calculate average time taken by each filter.

Details:

1. I wrote a singleton object to maintain average times.

2. I am adding System.currentTime() in each filter doFilter() method start and end & at end setting these values to request.

3. In the servlet, I am adding these times & incrementing the requests count in the singleton object.

Till this point it is working properly.


But, In the first filter starting, I have to send this counters values by reading from singleton object to some monitoring logs.
Here is the problem.

Parellel requests causing inconsistent time values... Any ideas please???
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My initial thought was to use the session id of the request to separate the requests, but a user with multiple tabs could still send simultaneous requests. You could try adding a UUID as an attribute to each request in the first Filter.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think about different methods of storing time values, other than in an object, e.g database, text files, etc.
 
Sheriff
Posts: 28330
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see why parallel requests should cause a problem, unless perhaps your strategy was to pass this singleton object a starting timestamp and a finishing timestamp and ask it to calculate the difference.

If you had code in the filters which used local variables to calculate the running time and then pass the result to this singleton object, you would just need a tiny bit of synchronization in the singleton to remove the issue.
 
Mani Venkata Kanth
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, Thank you for your replies.

Paul, Yes... I am calculating start & end times in the filter and finally setting time diff to singleton. Yep, I did synchronization. It is hitting some performance issues.
Any more ideas please???

Paul Clapham wrote:I don't see why parallel requests should cause a problem, unless perhaps your strategy was to pass this singleton object a starting timestamp and a finishing timestamp and ask it to calculate the difference.

If you had code in the filters which used local variables to calculate the running time and then pass the result to this singleton object, you would just need a tiny bit of synchronization in the singleton to remove the issue.

 
This one time, at bandcamp, I had relations with a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic