View Single Post
Old 06-14-2008, 09:53 AM  
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by elron View Post
I've bought Power Redirector and it looks like im gonna cancel the transaction , it works fine if u need to redirect just one or two countries , but if u have like 30 (in my case) it hits the sql DB 30 times and searches over the entire ip list each time , and that causes serious SQL overload .
Haha. Wow.

This is the problem you find when people who aren't very seasoned decide to make software, and design it entirely wrong. The smartest move would be to convert the dotted quad to a long, and run a binary search on it from the prepopulated tables.

Something like:
Code:
  BinarySearch(A[0..N-1], ip) {
      low = 0
      high = N - 1
      while (low <= high) {
          mid = (low + high) / 2
       if (ip <= A[mid].EndIp) {
            if (ip >= A[mid].StartIp) {
            return true;
        } else {
            high = mid - 1;
        }
       } else {
        low = mid + 1
       }
      }
      return false
  }
Would be at least O(log n), which is going to be as good as you can do with MySQL, anyhow.

.. or, you could install mod_geoip2, and get the country code with every request, then do the world's lamest switch statement. It'd still be faster.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote