Very slow download speed using Java in Raspberry Pi 3

I wrote the following code in Java to upload a file in 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();
}

Despite the fact that I use an 8 KB buffer, the average download speed is 1389 V around 205 ms, which corresponds to 6.78 KB / s:

Loading measurement speed

I also noticed that CPU usage when executing this code is always 25%. Since the RPi processor has 4 cores, I believe that it uses 100% of one core. I know this is a weak processor, but downloading a file is not a difficult task, so this strange behavior puzzles me.

+4
source share
1 answer

, , !

OpenJDK Oracle JDK:

sudo apt-get purge openjdk-8-jdk
sudo apt-get purge openjdk-8-jre
sudo apt-get autoremove
sudo apt-get install oracle-java8-jdk

Oracle JDK , java -version - :

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

5 / 450 /, 4 /.

OpenJDK , , jdk , pvg.

!

+4

Source: https://habr.com/ru/post/1680086/


All Articles