[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r14881: (ticket:86) Reverting from GeoIPs cache, seems to be very sl (torstatus/trunk)



Author: kasimir
Date: 2008-05-31 21:53:40 -0400 (Sat, 31 May 2008)
New Revision: 14881

Modified:
   torstatus/trunk/tns_update.pl
Log:
(ticket:86) Reverting from GeoIPs cache, seems to be very slow

Modified: torstatus/trunk/tns_update.pl
===================================================================
--- torstatus/trunk/tns_update.pl	2008-06-01 01:43:07 UTC (rev 14880)
+++ torstatus/trunk/tns_update.pl	2008-06-01 01:53:40 UTC (rev 14881)
@@ -57,6 +57,8 @@
 
 # Caching constansts for increased speed
 my %CACHE;
+my %geoIPCache;
+my %hostnameCache;
 
 # Counter for updating mirror list
 my $updateCounter = 0;
@@ -94,9 +96,6 @@
 	use RRDs;
 }
 
-# Geo::IP needs to be loaded - include a built-in cache
-my $gi = Geo::IP->open($config{'GEOIP_Database_Path'} . "GeoIP.dat",GEOIP_MEMORY_CACHE);
-
 # Loop through until killed
 while (1 == 1)
 {
@@ -165,9 +164,6 @@
 			$query = "UPDATE Status SET geoip=NOW();";
 			$dbresponse = $dbh->prepare($query);
 			$dbresponse->execute();
-			# Reload the GeoIP database
-			undef $gi;
-			$gi = Geo::IP->open($config{'GEOIP_Database_Path'} . "GeoIP.dat",GEOIP_MEMORY_CACHE);
 		}
 	}
 
@@ -686,6 +682,9 @@
 
 ############ Updating network status #########################################
 
+# Geo::IP needs to be loaded - include a built-in cache
+my $gi = Geo::IP->open($config{'GEOIP_Database_Path'} . "GeoIP.dat",GEOIP_MEMORY_CACHE);
+
 # Delete all of the records from the network status table that is going to be
 # modified
 $dbh->do("TRUNCATE TABLE NetworkStatus${descriptorTable};");
@@ -770,17 +769,33 @@
 		$currentRouter{'ORPort'} = $7;
 		$currentRouter{'DirPort'} = $8;
 
-		# We need to find the country of the IP
-		$currentRouter{'Country'} = $gi->country_code_by_addr($6);
+		# We need to find the country of the IP (using caching)
+		if ($geoIPCache{$6})
+		{
+			$currentRouter{'Country'} = $geoIPCache{$6};
+		}
+		else
+		{
+			$currentRouter{'Country'} = $gi->country_code_by_addr($6);
+			$geoIPCache{$6} = $currentRouter{'Country'};
+		}
 
-		# And the host by addr
-		$currentRouter{'Hostname'} = lookup($6);
-		# If the hostname was not found, it should be an IP
-		unless ($currentRouter{'Hostname'})
+		# And the host by addr (using caching)
+		if ($hostnameCache{$6})
 		{
-			$currentRouter{'Hostname'} = $6;
+			$currentRouter{'Hostname'} = $hostnameCache{$6};
 		}
+		else
+		{
+			$currentRouter{'Hostname'} = lookup($6);
+			# If the hostname was not found, it should be an IP
+			unless ($currentRouter{'Hostname'})
+			{
+				$currentRouter{'Hostname'} = $6;
+			}
+			$hostnameCache{$6} = $currentRouter{'Hostname'};
 		}
+		}
 	}
 
 	# Format for the "s" line