开发者

Finding closest server based on user ip?

Users will be uploading files to my servers. In perl, how could I detect which serv开发者_如何学编程er would be most suitable given a list of server ips and the users ip? I looked at MaxMind but it would only tell me the location of ips. How would I find the closest one?


perhaps I am missing something but

IF you know the location of the IPs (of the servers and the user via MaxMind) just calculate the distance between every server ip versus the user ip and choose the smallest one...

EDIT - as per comment:

The physical distance doesn't say much about performance... OTOH for measuring/comparing performance you would need to send test packets between the user and the servers and then compare/decide...

EDIT 2 - as per comment:

IF you only have one server per continent then the calculation is rather easy... check the continent of the user IP and choose the server accordingly since it is usually pretty safe to assmue that servers on a continent different from the user would perform worse...


do you need the closest server or the fastest server at any moment ?

In case you need to find the best performing server , you may want to send a test packet and get the response time for each to find this out.

In case you need to find the closest, then you may count the number of hops between each destinations to pick the closest.

PS : I am not that well acquainted with perl to give you a perl specific command for this.


If they're going to do it more than once, you could log all uploading IPs (or class C blocks), then run a one-off traceroute/ping from each server, and retain that for to use the next time they upload.


If it's actual geographic location you're after, then that can't be reliably determined from an IP address, although you can get pretty far with heuristics using DNS or third-party services such as MaxMind.

But if you're after the shortest network distance, which is some indication of the expected response time, then you can check the TTL field of the packet header: a lower TTL means the packet travelled farther. It's not foolproof since different OS vendors use different default TTLs, but it's an option.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜