Answer the question
In order to leave comments, you need to log in
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
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.
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 questionAsk a Question
731 491 924 answers to any question