• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do filters affect web application performance?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I want to know if filters affect performance of a web application.

If I add 1 filter then is it going to make my application slow?

And if I add 2, 3 or 4 filters is my web application [not that I will add , but I want to know] going to be slow with each filter that I add?

How will filters behave in JSF application? What is recommended, using PhaseListener or Servlet Filter or it does not really matter?

Suppose if I have one phase listener and 1 servlet filter then will it affect performance of web application?

-Regards
Ajay
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ajay Kamble wrote:I want to know if filters affect performance of a web application.

If I add 1 filter then is it going to make my application slow?


...

Wouldn't it depend on what the filter does?
 
Ajay Kamble
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So do you mean that filter does not affect performance?

Let me put my question in a different way- suppose I want to do authentication for my web application.

Case 1: I wrote some Utility class to do this authentication for me, I call it from each servlet.
Case 2: I wrote this same code in filter.

Now, just because I use filter in case 2 is my web application going to be slower than case 1? Does filter add any overhead and make my web application slow?

Suppose I keep increasing number of filters to 4, 5 then is it going to affect performance?

And again what about PhaseListeners of JSF. Do they add any overhead?

-Regards
Ajay
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ajay Kamble wrote:So do you mean that filter does not affect performance?



Not necessarily.
As David said, it depends on what your filter is doing.
If the code in your filter does something expensive (like created database connections to read large amounts of data) then, yes it will slow things down.

If you're asking if filters in and of themselves cause a big hit to performance, no.

It wouldn't be hard to test.
Create a simple hello world app (or download one here), hit it a couple times to see how fast it responds.
A tool like firebug will show you response times for requests.
Then add a filter and hit it some more.
Keep adding filters and keep hitting it. You'll know for certain, exactly how much of a performance hit a filter causes.

Another test that will give you some perspective would be to take a hello world servlet and throw a RuntimeException in it.
Then look at the stack trace in the logs. When you see how many components a typical requests goes through you'll realize that one more is fairly trivial.

 
Ajay Kamble
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you're asking if filters in and of themselves cause a big hit to performance, no.



Thanks Ben and David, I got my answer.

-Regards
Ajay
 
reply
    Bookmark Topic Watch Topic
  • New Topic