Small file with many seeks, or large file with one seek ?

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Consider a common IP address to country code map. Stripped down to bare essentials for looking up the country code the common file will have an int for the beginning and end of the range along with a country code.

Using such a structure, no engine I know of be it a database or flat file, can pinpoint the position of a an IP address without doing multiple seeks that involve calculations to both parse the range and find the next position in-between each iteration.

If you create a single 4GB file with a single byte relating to each country code, all you have to do is convert the IP to an INT, open the file, and seek to the position of that INT in the file to read the byte that tells you what you want to know.

We have to take into consideration that most of the time an IP map in the first situations format would only be a couple MB in size VS the 4GB for the second method. Meaning it would be a lot easier to hold the first methods entire file in memory.

It's not uncommon to find servers with 16GB of memory in them these days though, so realistically we should be able to store the entire data set for the second method in memory as well.

But assuming this is a server where only the first method could have its' dataset kept in memory, would you rather use the first method with multiple calculations and seeks, or the second method that would be forced to always work with the disk that would require one seek ?

Considering this is mapping IP to country, chances are it's going to be something that gets done with every single visitor.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 67 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.