3

The system I am developing potentially has a very large number of clients (lets say one million) that need to periodically update a central server with some information. Clients are written in Java.

The specific use-case is that the server backend needs to have an up to date mapping of IP address to clients. But the client IPs are dynamic and subject to (effectively random) change.

The solution I have in mind requires the clients to ping the server to update their IP. The period ideally should be once every minute, but even 1 ping/10 mins is acceptable.

My questions, in sequence:

  1. 1M pings per 1 min is over 10k/sec. So first off I want to know the approaches can scale to handle such a load. This is to know the options available.

  2. Assuming you have more than one solution in mind, which of these would be the most economical? The cost effectiveness is critically important. I don't have my own data center or static and fat end-point on the net, so the server application will need to run on some sort of provider or ultimately on the cloud.

Notes:

  • I considered running the server from home using my own ISP provided connection, but I am neither sure of the performance issues, nor what my ISP will think about a constant stream of pings.

  • I can't see how the server can auto-discover these IP changes.

alphazero
  • 27,094
  • 3
  • 30
  • 26
Erik
  • 5,039
  • 10
  • 63
  • 119
  • 1
    Why do they need to send their IP-address to the server? – Thorbjørn Ravn Andersen Mar 31 '12 at 11:37
  • because i have mobile devices connecting to the computers and they need to query the above server for the computer ip address. Since there is no way for the computer to establish a connection to the device, the device need to initiate the socket connection – Erik Mar 31 '12 at 11:44
  • What do said mobile devices need to do? – Thorbjørn Ravn Andersen Mar 31 '12 at 11:45
  • The computer will transfer files to the device after the device have opened a connection. This is the app https://play.google.com/store/apps/details?id=com.hellberg.spriid&hl=sv – Erik Mar 31 '12 at 11:47
  • add yourself as a friend to test the app – Erik Mar 31 '12 at 11:53
  • For iPhone you can push messages. COuld the same be done for Android? Then the push message cause the device to call home to see why. – Thorbjørn Ravn Andersen Mar 31 '12 at 14:10
  • @Thorbjørn Ravn Andersen Yes Android has C2DM with is what i understand same as iPhone push. I push messages from the server to the devices. That's the only way i can contact all devices. The device then connect to my server to get ip address of the computer that is sending files to that particular device. – Erik Mar 31 '12 at 14:21
  • @Erik it really depends on "how scalable" the solution needs to be and what you mean by "cost effective/expensive"... another point: why every 60 s ? in my experience IP change usually happens once in 24 hours, never saw it happens below 30 minutes... please provide much more details... – Yahia Apr 15 '12 at 19:31
  • @Yahia Through the java program i cannot know when if ip change. If I update every 24 hour the server could really have the wrong ip for 23 hours and 59 minute 55 second. So 60s or even 10 min should cover it. I'm doing this in java simply because I want to target many dif systems. "cost effective/expensive" is simply a solution that works, cheapest money cost is of course nice. I dont think my question is abstract it just need the right person reading it, hence the bounty – Erik Apr 16 '12 at 04:22
  • @Erik I am not saying it is abstract - it lacks a lot of details... and "cheapest" might be less reliable... without more clarity you only get some speculative answers... – Yahia Apr 16 '12 at 04:33

6 Answers6

2

Maybe you could use SIP as protocol for that purpose ? Probably the java SIP libs already solved your problem.

Nice app by the way.

Ruediger
  • 271
  • 1
  • 4
2

Erik, your problem is much simpler than it seems to have been made to sound.

This problem been around for a decade maybe two. No need to re-invent the wheel here.

Why Polling/Pinging is a Bad Idea

The dynamic IPs provided by ISPs can have a variable lease time, but will often be at least 24-72 hours. Pinging your server every 1-10m will be a horrible waist of resources potentially making over a 4,320 useless HTTP requests PER CLIENT in a 72 hour period. Each request will be say around 300 bytes * 4,320 wasted http requests equals 1.3mb wasted bandwidth multiplied by your target client count of 1 million clients, you are talking about a monthly wasted bandwidth of ~1.2 TB! And that's just the wasted bandwidth, not the other bandwidth you might need to run your app and provide useful info.

The clients need to be smarter than just pinging frequently. Rather they should be able to check if their IP address matches the DNS on startup, then only when the IP changes, send a notification to the server. This will cut down your bandwidth and server processing requirements by thousands of times.

What you are describing is Dynamic DNS

What you are talking about is "Dynamic DNS" (both a descriptive name for the technology and also the name of one company that provides a SaaS solution).

Dynamic DNS is quite simply a DNS server that allows you to very rapidly change the mapping between a name and an IP address. Normally this is useful for devices using an ISP which only provides dynamic IPs. Whenever the IP changes for the router/server on a dynamic IP it will inform the Dynamic DNS server of the change.

  • The defacto standard protocol for dynamic DNS is well documented. Start here: DNS Update API, I think the specifics you are looking for are here: DynDNS Perform Update. Most commercial implementations out there are very close to the same protocol due to the fact that router hardware usually has a built in DynDNS client which everyone wants to use.
  • Most routers (even cheap ones) already have Dynamic DNS clients built into them. (You can write your own soft client, but the router is likely the most efficient location for this as your clients are likely being NAT'd with a private IP - you can still do it but at a cost of more bandwidth for public IP discovery)
  • A quick google search for "dynamic DNS java client" brings up full source projects like this one: Java DynDNS client (untested, just illustrating the power of search)

Other Considerations for your System Architecture

Lets say the IP-client mapping thing gets resolved. You figured it all out and it works perfectly, you always knows the IP for each client. Would you then have a nice reliable system for transferring files to clients from mobile devices? I would say no.

Both mobiles and home computers can have multiple connection types, Wi-Fi, Cellular Data, maybe wired data. Each of these networks may have different security systems in place. So a connection from a cellular data mobile to a wifi laptop behind a home router is going to look very different than a wifi mobile device connecting to laptop on the same wifi network.

You may have physical router firewalls to contend with. Also home computers may have windows firewall enabled, maybe norton internet security, maybe symantec, maybe AVG, maybe zone alarm, etc... Do you know the firewall considerations for all these potential clients?

BenSwayne
  • 16,810
  • 3
  • 58
  • 75
  • thanks for the breakdown. Your DNS solution should work i think. All clients will query the same dyndns account. and can by doing that see if IP has changed. Is this what you initially meant? That way the client will only ping server if ip has changed. About the firewall problem and how each java client will get the inbound connection, I think UPnP maybe can be used to create port forwarding, not sure. The idea is that the client program is installed on a fixed home pc. If they install it on a Wi-Fi laptop that ip-jumps all day, they have to simply not install the client on that laptop. – Erik May 02 '12 at 16:41
1

I would suggest better tweak you java program to know the IP change and then only hit the web service.

You can do it like,

  1. on your java program initiation extract the IP of machine and store it in Global variable or better some property file.
  2. Run a batch process/scheduler which will check your IP every 30sec/1 minute for change.Java Quartz Scheduler will come very handy for you.
  3. Invoke the web service in case of a change of IP.

This way it reduces your server role and thus traffic and connections.

shashankaholic
  • 4,122
  • 3
  • 25
  • 28
  • That will only work if the computer is directly connected to Internet and therefore has the WAN ip. – Erik May 02 '12 at 17:19
1

You could create your own protocol on top of UDP, for example XML based. Define 3 messages:

  • request - client requests a challenge from server
  • challenge - server replies with challenge (basically a random number)
  • response - client sends username and hashed password + challenge back to the server

It's lightweight and not too traffic-heavy. You can load-balance it to multiple servers at any layer or using load-balancer.

Any average PC could handle million such hits per minute, provided you do server-side in C/C++ (I don't know about java network performance)

Kveri
  • 380
  • 2
  • 13
  • I agree that UDP is the smart choice here. +1 (FYI, Java network performance is quite good. The only issue is running a JVM on a budget is going to bust memory quotas for budget hosting options.) – alphazero Apr 22 '12 at 14:49
0

Please have a look at how no-ip works. Your requirement is exactly same as what it does.

Kannan
  • 116
  • 1
  • 6
0

Do I have the use case right? A community of users all want to receive pictures from each other? You don't want to host the images on the server but broadcast them directly to all the users?

There are two questions here. The first question is "how to know if my own WAN IP address has changed."

If you are not NATed then:

InetAddress.getLocalHost()

will tell you your IP address.

If you are NATed, then using dynamic DNS and resolving your own host name will work.

The second question is something like "How to share pictures between hosts which come and go on the internet".

The possible solution space includes:

IP Multicast, probably with Forward Error Correction and Carouseling, e.g. FLUTE.

File Swarming - e.g. bittorrent.

A Publish/Subscribe message bus solution using Jabber, AMQP, JMS, STOMP or similar. Suitable implementations include RabbitMQ, ActiveMQ, etc. JMS Topics are a key concept here.

The solution should avoid the massive overheads of doing things at the IP level.

Julian
  • 1,522
  • 11
  • 26
  • thanks for the incite. It's really grate to get a comment like that. I have a loot of reading to do :) The reason why files are not sent directly is because of the the flaky networks most mobile devices will have. This way the sending/receiving device will be connected to a no-flaky Server and increase send/rec speed. I know there are better ways and this is the best i could do for know – Erik May 02 '12 at 16:58
  • Dynamic DNS doesn't really help here - the server's IP and DNS are static and known. Its a publsh/subscribe problem. If you think the networks are flaky in a packet loss sense then you might want Forward Error Correction (FLUTE is a canonical solution) but actually this also looks like a file swarming scenario (e.g. bittorrent.). Also look at chat applications with file transfer. – Julian May 02 '12 at 17:25
  • I thought that a computer java client could ping a dyndns and get a reply back and therefore read his own WAN ip address.? Then the client would not have to ping the server every 60sec, only when WAN ip have changed. Maybe im fishing in the wrong water.. – Erik May 02 '12 at 18:10
  • you can query your own address from the interface InetAddress addr = InetAddress.getLocalHost(); but why would you need to? If you have a subscription to a message bus the stack will take care of disconnects and reconnects and you can just wait for data. – Julian May 02 '12 at 18:38
  • There are two questions here. The first question is "how to know if my own WAN IP address has changed." If you are not NATed then: InetAddress.getLocalHost() will tell you your IP address. If you are NATed, then using dynamic DNS and resolving your own host name will work. – Julian May 03 '12 at 07:54
  • i think the dynamic DNS is the answer for part of the question. This way client only connect to server when ip has changed. The Publish/Subscribe i will have to read up on. One device send to one or many other devices including PC. Thanks – Erik May 03 '12 at 15:33