Net neutrality: Is my internet being throttled?

-4

2

From the wikipedia:

Net neutrality is the principle that Internet service providers and governments regulating the Internet should treat all data on the Internet the same, not discriminating or charging differentially by user, content, website, platform, application, type of attached equipment, or mode of communication.

Your task is to find if your internet connection is being throttled by your ISP or if the net is neutral.

What you actually have to do

Your program or function will be run twice. It needs to have some form of memory or storage between its two calls, like writing to a file, a static var in C++, setting a property on a function in JS, or just a global variable.

The first time it is run, it must connect to google.com (a fairly popular site), and a different website with an Alexa rank of greater than 1 million, like unlicense.org.

It must record the time it took google.com to respond*, and the time it took the other website to respond*.

The second time it is run, it must do the above, and print a truthy value if these are both true:

  1. The response time between google.com the first and second time varied by less than 5%. (Google paid ISP to not throttle)
  2. The response time between the other site the first and second time increased by more than 50%. (Other site didn't)

Shortest code wins!


* The time it to get the response body, headers, or just connect with the server. You choose.

programmer5000

Posted 2017-07-16T22:40:13.257

Reputation: 7 828

2Is there any method you could recommend of finding such a site with an Alexa ranking greater than 1 million? – notjagan – 2017-07-16T22:47:04.867

@notjagan done. – programmer5000 – 2017-07-16T23:04:00.287

Why the downvotes? – programmer5000 – 2017-07-16T23:04:59.287

To clarify, you mean a site with a larger rank and thus lower traffic, right? I at first thought you meant a high rank. – Rɪᴋᴇʀ – 2017-07-16T23:11:18.463

Also, theoretically, wouldn't it be a much longer time based on the location of the site's servers? – Rɪᴋᴇʀ – 2017-07-16T23:11:44.823

@Riker Yep. Latency and ping would do a good lot, but unlicense is run by github, so servers for both sites should be pretty well distributed. – Zizouz212 – 2017-07-16T23:13:51.923

1Also, the time to get the full response body is pointless. It will take much longer to download larger bodies than others. Google is likely a much smaller body than unlicense. You should be measuring the time between when the request is submitted, and the first headers are received. – Zizouz212 – 2017-07-16T23:15:25.430

I think having to run it twice is a bad idea. One run please? – Christopher – 2017-07-17T00:55:42.977

@Zizouz212 fixed. – programmer5000 – 2017-07-17T15:48:28.627

Answers

4

Python 3 + requests, 185 bytes

lambda t=[]:t.append([g("http://google.com"),g("http://a.co")])or len(t)>1and abs(1-t[0][0]/t[1][0])<.05<1.5<t[1][1]/t[0][1]
g=lambda s:get(s).elapsed.microseconds
from requests import*

Unfortunately requests doesn't work with TIO, so I'll have to post a link on another service later. Uses http://a.co as the website with a ranking greater than 1 million.

207 bytes, if time is required for the full body

f=lambda t=[]:t.append([g("http://google.com"),g("http://a.co")])or len(t)>1and abs(1-t[0][0]/t[1][0])<.05<1.5<t[1][1]/t[0][1]
def g(s):t=time();get(s);return time()-t
from requests import*
from time import*

notjagan

Posted 2017-07-16T22:40:13.257

Reputation: 4 011

Your answer is basically what I wrote too. The problem with the elapsed attribute of a request is that it's the measured time between when the request was submitted outbound, and when the module first started parsing the first response headers that it received. Not the full response body :) – Zizouz212 – 2017-07-16T23:47:51.760

@Zizouz212 Wouldn't it make more sense for it to measure the time to response headers? The full body would be dependent on the size of the page and not solely the time to connection. – notjagan – 2017-07-17T00:06:03.070

Oh no, I completely agree. I even mentioned it in the comment above on the question as well (I wrote nearly the same answer with python 2 requests). It's just the question wants the time for the response body to arrive as well, which I figured I'd just mention – Zizouz212 – 2017-07-17T00:12:33.050

Since requests is an external library that isn't in vanilla Python (which is why it isn't on TIO), officially your header should say Python 3 + [requests](http://docs.python-requests.org/en/master/), just a heads up – Value Ink – 2017-07-31T22:38:38.583

@ValueInk But requests is part of vanilla Python - in fact, you can import it on TIO. The problem with it on TIO is you can't actually make requests (i.e. through requests.get) because TIO restricts network access. – notjagan – 2017-07-31T23:11:40.243

Really? I just tried it on my Python 3.5.2 and got a ImportError: No module named 'requests'. The requests website also tells you to run pip install requests to install it. Wonder what's up with that (maybe the TIO machine has it installed already?) – Value Ink – 2017-07-31T23:26:29.010

@ValueInk Ah, it seems I was mistaken since requests is just so ubiquitous - it's not actually a standard library. requests is most likely just a module pre-installed on TIO since it's so common; other such modules include numpy. – notjagan – 2017-07-31T23:40:55.883

requests doesn't work with TIO because the TIO arenas can't access the internet at all. This is a restriction that is unintentional and will likely not change. It is due to the internal arena communication servers, and some VPN/DNS/SomeFancyInternetStuff ... obnoxiousness. – MD XF – 2017-08-23T01:56:26.723