• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to improve IP range check?

 
Michal Glowacki
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I would like to put some stress away from the database. I have ip ranges (say, ip_start, ip_end, blocked) table from which I check if customer should be allowed to view my page. I make check just once, when he comes to the page and his session bean is created. But still it hit's perfomance I believe. It would be nice if could load ip range database into memory and make check from it, right? But it is very difficult for me to design this solution right.

Maybe someone have an idea to help?

Michal
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But still it hit's perfomance I believe.

That's not enough of a basis to make modifications for the sake of performance. You need to be certain where the delay originates. This sounds like a simple check in a simple table, which should not take long at all. What is the query you're running? What size is the table? Are you using indexes?
 
Michal Glowacki
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've made several thread dumps, often I can see that jdbc is waiting to run query from my ip check method.

I use indexes, size of the table have more than 80k rows (4 columns). But I only would like to cache the allowed ranges (40k rows). Query looks like this:

 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to use the DB's query analyzer (or EXPLAIN option, or whatever it's called for the DB you're using) to make sure that the index is used for this particular query, and that there's not a table scan going on.

Is the query slow as well if you run it directly from the DB's command-line tool?
 
rajesh bala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cant ip range checks be set as a bunch of rules in apache or your webserver itself?

~Rajesh.B
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rajesh bala:
Cant ip range checks be set as a bunch of rules in apache or your webserver itself?


Extending rajesh's idea: if its important and slow to use JDBC, don't use JDBC. I'm not sure I understand why you are doing this, but normal blacklist of IP addresses are fairly compact, you could load up a nice structure in memory once when the application/web service starts and do it in memory.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic