Any production-ready Elixir libraries for managing internet connections?

Are there any production-ready Elixir libraries for managing internet connections, similar to monitor-internet-connection.py?

3 Likes

What would make it ‘production ready’ for you? If it is about reliability, a Genserver under a Supervisor would do.

The Python versions is not an example of defensive code style; which it could use for this use case as you don’t want your monitor to go down (and yes, it did see the generic OSError handler). I assume it is expected to be wrapped in try/catch in the using code. If one fails to do so, it seems is can bring the whole program on it’s knees.

You may simply run this module in a console/terminal and leave it running for days/weeks on end.

The Elixir version doesn’t have to be written defensive due to the Supervisors. Even when is sucks (which is given the limited use case almost impossible), it would not take the whole program out with it.

So even a simple Elixir version is more reliable than the Python version. You could replicate the py-file within an hour with benefits of OTP. For me that would be instantly production ready.

The Elixir version run for years on end without any problems.

ps. I highly doubt this would ever be an Elixir lib. Maybe a Gist is a better fit as it’s only one file and there is no need for advanced coding in Elixir to accomplish this.

5 Likes

Interesting proposition. Say a particular internet connection goes down how would I go about cycling through other available connections until it finds a stable one? (I’m on an Ubuntu machine.)

1 Like

What is a stable one? :slight_smile: Stable is not objective so hard to say without knowing your interpretation of ‘stable’.

Having my fair share of connection related code, I can assure you that no connection ever can be assumed to be ‘always connected’. As Erlang (where Elixir is build upon*) was build with exactly that in mind, Elixir is the perfect language to build the monitor with.

*keeping it simple

2 Likes

I appreciate you asking. I’m referring to a connection that stays active as opposed to one that finds it challenging to stay connected to the internet. It would be ideal if the system could immediately switch to a different network the moment it detects that the current connection has failed, makes sense?

1 Like

I guess I"m sort of confused about the kind of system you’re talking about. When do programs you write manage connections and switch between “connections”? Most of the time servers have exactly one public internet connection, can you elaborate on the circumstances you’re designing a program to operate within?

2 Likes

Me too :lol:

My first thought was some sort of scraper that is getting IP banned but in that case you’d just retry or log (and defer to another instance) on failure.

(internet-connection.py) is a Python module to monitor the uptime of the Internet connection - that is to say to monitor that an external IP address is always reachable.

If it’s a specific IP address that you want to check (i.e not your own connection but uptime of some ip/url) then you could build a small Phoenix app to do it. I made something similar in Ruby some years ago when a leading domain registration company failed to register a domain even tho the payment and all confirmation emails went through as usual - they said it was in their terms that we had to verify domains had actually been registered ourselves!!! It was a client domain and it cost us a lot of money to get back so I built a small app to check our domains once a day and then send us an email if they didn’t resolve or resolve to the correct IP (and/or didn’t show specific content we were expecting). I was actually planning on converting it to Phoenix app one day and offering it as a service as it would be a perfect fit for Elixir due to the sheer amount of domains that might need to be checked.

For general uptime checks you could do similar, just check every minute and log successes and failures.

3 Likes

If my WiFi connection dropped, how would I go about restarting it from within the Elixir app?

1 Like

It seems you don’t need (not even should want) a lib/app for this but some OS specific config. I know our office MacBooks have one as the Wifi stack of MacOS is….surprising. Ubuntu probably has some (low level) settings for it too.

  • Connects and disconnects of interfaces is logged by the OS.
  • When you want to track an external server, Elixir can do so. But it won’t manage the interfaces as that’s the job of the OS.

You can combine both to check what was the cause of the ‘unreachable’ error (logging).

2 Likes

Why do you need to do that tho Max? Usually if your Wifi connection drops your OS will reconnect. Are you serving an app from your home machine? (Not a great idea, you may be better off using a free-tier of one of the Elixir-specific hosts.) Or is it some script you’re running? (If so can you just pause it or set to retry until your OS reconnects you to the network?)

2 Likes

Thanks for the suggestion. Which would you recommend?

2 Likes

These two come to my mind:
https://www.gigalixir.com/
https://fly.io/

3 Likes

Wow, that pings google once per second… I know they are a friendly bunch and eat the bandwidth cost for this, but that’s quite a chunk of bandwidth !!

2 Likes

Then you realize Google owns Youtube and serves 4k-resolution videos. They won’t even notice when they look at their data usage with a microscope :slight_smile:

Just for fun the stats…

https://everysecond.io/youtube

When a client sends a DNS query to your DNS server, normally the packet length is between 50 and 550 bytes (including the IP header). So in worst case, the script will consume 47.52 megabytes per day.

The average video length is 11.7 minutes. A 1080p video Youtube uses 5mbps. This makes the average video consume 412.5 megabyte of data for one single view.

So in the worst possible scenarion, a single view of an average 1080p Youtube video consumes 9 times more data then the script in a whole day. Factor 10 for the scenario in which the DNS connect only takes 55 bytes.

The worst case scenario would be 1.2762029e-8% of their outgoing traffic!

When the whole world population would use the script, it would cost them 368,280 terabytes per day. That would make a dent: it comes close to the 440,000 terabytes Youtube uses per day.

But rest assured, one can run the script 10,476,190,500 days (28,701,891 years) before it has used one day of Youtube data. I bet the connection drops before that ever happens :wink:

Ps. I know CDN, ISP cache, upload vs. download, math is hard etc. Let’s get back on topic

2 Likes