M
M
Michael2016-10-07 08:21:00
SQL
Michael, 2016-10-07 08:21:00

How to quickly determine the city and country by IP?

There is a maxmind database (cities, countries and IPs).
Now the data is stored in MS SQL database and the IP check occurs with each user request to the API.
Accordingly, a huge number of select requests to the database for IP search and the load on it.
What are the ways to quickly determine the city and country? What that not relational bases? Or something else?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
romy4, 2016-10-07
@Sing303

Addresses are allocated by pools and, in principle, you can safely use the list of pools / 24 - this is 16 MB in total. which can be easily stored in a table in memory. Calculate the offset and take the country index by the offset (there are no more than 255 countries in the world). So the task is quite feasible for a quick search.
In this case, the table may not be stored in the database at all (the gain is at least in the time of sending packets), but in a vector, then you will get the maximum gain.

D
Dmitry Eremin, 2016-10-07
@EreminD

caching, for example

M
Maxim, 2016-10-07
@pudovMaxim

One simple select in the database should not load it much if the database is properly designed. Represent IP, for example, as a number and make the field index (although it may be difficult with IPv6, you need to check).
Also, if the memory on the server allows, then you can transfer this tablet to the RAM or cache it with any convenient cacher.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question