Web Hosting Info

Search:

featured partner

The IP to Country Database

  Forum Topics : Development / Counter
Submitted by zdrang on Tue, 03/30/2004 - 10:18.
Well, could someone please suggest me a counting method to count time it takes the database to reply in milliseconds?

Thank you,
Alexandru Surpatean.
Comment viewing options:
Select your preferred way to display the comments and click 'Save settings' to submit your changes.
Which scripting language?
Posted by cruzit on Tue, 03/30/2004 - 22:36.
ASP I can help. CFM someone else may help.
 
Sorry :-)
Posted by zdrang on Tue, 03/30/2004 - 22:58.
Sorry for not including this info! :-)

I would preffer PHP (ASP is not supported on my hosting)
Supported on my hosting: Perl, PHP4, Python, Ruby and TCL, but as sead, I would preffer PHP (never worked with the others)

Thank you,
Alexandru Surpatean.
<? //------------
Posted by amit on Thu, 04/01/2004 - 05:40.
<?

    //---------------------------------------------------
    // Sample code to display Visitor Country information 
    // PHP 4 
    //---------------------------------------------------

    function getmicrotime()
    {
      list($usec, $sec) = explode(" ", microtime());
      return ((float)$usec + (float)$sec);
    }


    // Establishing a database connection
    $dbh=mysql_connect("localhost:3306","$MYSQL_USERNAME","$MYSQL_PASSWORD");
    mysql_select_db("$MYSQL_DBNAME");

    $start_time = getmicrotime();

    // Query for getting visitor countrycode
    $country_query  = "SELECT country_code2,country_name FROM iptoc ".
         "WHERE IP_FROM<=inet_aton('$REMOTE_ADDR') ".
          "AND IP_TO>=inet_aton('$REMOTE_ADDR') ";


    // Executing above query
    $country_exec = mysql_query($country_query);

    $end_time =  getmicrotime();



    // Fetching the record set into an array
    $ccode_array=mysql_fetch_array($country_exec);


    // getting the country code from the array
    $country_code=$ccode_array['country_code2'];


    // getting the country name from the array
    $country_name=$ccode_array['country_name'];


   // Display the Visitor coountry information
   echo "$country_code - $country_name";


   // Closing the database connection
   mysql_close($dbh);

   echo "Time taken by the query - ".($end_time-$start_time);


?>

Also make sure that you have created a composite index on your (IP_FROM,IP_TO) fields... -
Amit Bhawnani
another humble employee.
 
Smallest
Posted by zdrang on Thu, 04/01/2004 - 11:55.
Thank you Amit,

It works perfect but I have another question..
What's the smallest value an algorithm ever got?

I mean,
With the database created as explained in this forum and the basic algorithm I've got a 0.022 responce..
After optimizations (bouth to the algorithm and to the database) I've got a 0.00045 responce to the same ip..
(of corse I've tested it several times)

What's the smallest value ever recorded by an algorithm?

Thank you,
Alexandru Surpatean.
 
Idea
Posted by sintnico on Fri, 04/02/2004 - 11:59.
Maybe it is a nice idea to show these optimalizations, so other people can use them as well.

Thanks in advance

sintnico

-----
PhPMyStats
 
Benchmarking
Posted by Daath on Thu, 04/22/2004 - 20:47.
When benchmarking with mysql, be sure to turn the query cache off, else you won't get a reliable read-out.
I'm also interested in performance. I did a conversion from the CSV to a binary format, and using microtime() in php, a look-up from file says a pp. 0.02 microseconds... No idea if that is correct though, since my python code runs the same with avg. 3 microseconds. I would have thought that python was faster...

-
Any technology distinguishable from magic, is insufficiently advanced.
 
Either there is a confusion o
Posted by zdrang on Thu, 04/22/2004 - 22:43.
Either there is a confusion or the scripts posted here would make Einstein proud of our generation..

A microsecond (according to the dictionary) is one millionth of a second..
So are you saying your query took 0.04 microseconds..
That would be 0.00000004 seconds.. I know I'm not a genius but that seams to me a little to quick..

Aren't you referring to milliseconds?
One millisecond is one thousand of a second..
So your query would take 0.00004 seconds..

So please express it in seconds so I get it too..

Thanks,
Alex.
 
Oh my
Posted by Daath on Fri, 04/23/2004 - 00:43.
Hehehe yeah you got me. I meant milliseconds of course (10^-3 seconds). I've been looking at the scripts again, and ran some tests, the python script is in fact faster averaging just under 3 ms per lookup (single lookup - subsequent lookups would be faster, I'm gonna have to test that later).
The php averages around 23 ms - same deal with subsequent lookups...
Still, I think it's pretty ok, considering that it's read from disk, and not a RDBMS.

Anyway, sorry for the confusion, I'm tired, it's 2:40 am here right now, and I've had a long day at work ;)

-
Any technology distinguishable from magic, is insufficiently advanced.
 
Better classes
Posted by Daath on Fri, 04/23/2004 - 01:29.
Played with the python code a bit, first lookup averages 2.8 ms - subsequent lookups are around 0.8 ms.

The php code averages 25 ms on first lookup, and 4 ms on subsequent calls...

Both still search on disk in the 467 KB binary "database" file.

I still can't believe I said microseconds :)

-
Any technology distinguishable from magic, is insufficiently advanced.
 
It's not that off, actually
Posted by Daath on Wed, 04/28/2004 - 15:00.
"That would be 0.00000004 seconds.. I know I'm not a genius but that seams to me a little to quick.."

Yes, we tested it again with my new C# code, looking up 18000 unique IP addresses, on average our max speed was 0.0000002 seconds per lookup, on a Centrino 1,6 GHz machine ;) That's 500000 lookups/second. I was amazed :) I even get 305000 lookups/sec on this P4 1,7 GHz that I'm sitting at right now.

-
Any technology distinguishable from magic, is insufficiently advanced.