I wrote the following code in Java for downloading a file in a Raspberry Pi 3:
String fileUrl = "...";
URL urlObj = new URL(fileUrl);
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
InputStream in = con.getInputStream();
byte[] buffer = new byte[8*1024];
long t = System.nanoTime();
int read;
while ((read = in.read(buffer)) != -1) {
System.out.println("Read " + read + "B in " + (System.nanoTime() - t)/1000000.0 + " ms");
t = System.nanoTime();
}
Even though I am using an 8 KB buffer, the average download speed is 1389 B in around 205 ms, which translates to 6.78 KB/s:
I also noticed that the CPU usage while executing this code is always 25%. Since the RPi's CPU has 4 cores, I asume it is using 100% of a single core. I know this is a weak processor, but downloading a file isn't a demanding task, so this odd behaviour puzzles me.