Java Performance Issues for Raspberry Pi

The purpose of this application is to process 800 concurrent clients over TCP, each of which sends 3.5kb xml every second. Each of these queries should be analyzed (see Code Snippet). This happens in different threads.

The limitation of this project is that it should work on a small Raspberry Pi3 (1.2 GHz quad core, 1 GB of RAM). And I encounter usage problems when I increase the load above 150 concurrent clients (80% of CPU usage).

When I run this program, my development machine seems to work very well. (0-1% of use, less than 150). I understand that my development machine is more powerful than RPI, and therefore works better. But the difference seems too big.

In my current setup, I use Java nio to process / read all incoming connections. Then I use several threads to read data.

Current setting

This is simple code that is currently executing in a processing thread. Also tried to read a simple byte [] array of 1 byte at a time. And even reading the StaX stream. Each reading variation I tried, the “reading type”, gives the worst performance.

BufferedInputStream input = new BufferedInputStream(new ByteArrayInputStream(buffer.array(), 0, bytecount));
int current;
/* In this snippet input.read() is the cause of performance issues 
Reading directly from byte[] gives similar poor performance.
*/
while ((current = input.read()) != -1) {
    continue;
}

According to my profiler, calling Input.read () uses huge processing power on the Pi and makes up 97% of the total processor time. the other 3% is the main thread that processes the connections.

On my development machine, this is almost upside down, and the main thread takes into account most of the processor usage, 93%. And 7% goes to processing flows.

? read() pi , - ?

:

  • Pi raspbian linux - openjdk 1.8.0_40-internal
  • Dev win 10 - Java (TM) SE Runtime Environment (build 1.8.0_121-b13)
  • -Xms -Xmx , .
+4
1

, JVM, 32- Raspberry Pi 3. 32- raspbian OpenJDK ( "" ). JVM Oracle "" .

64- (OpensSuse ) OpenJDK, JVM Oracle.

( @jww , 64- )

0

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


All Articles