Hello,
We are going to use T7 device in our system to collect data from sensors. Data is collected from single board computer based on Freescale Cortex-A9 i.MX6 Solo/Dual core 1.0 GHz (OS Linux 3.0). I got LabJackM-1.0707-Raspbian-Linux-armhf library and built stream_example to get data from AINs over Ethernet. But I noticed that during data read CPU load is too high. Scan rate is 2000 Hz. I got following results:
4 AIN channels: CPU load 36%
8 AIN channels: CPU load 73%
14 AIN channels: CPU load 109%
If I change sampling rate to 1000Hz I see CPU load drops about 2 times. So it looks like CPU load have linear dependency of amount of channels and sampling rate.
We have a lot of sensors and we can't use T7 if data read will spend all our CPU performance. When I run that application on my laptop (Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz, Linux) CPU load is about 16% for 14 AIN channels and sampling rate 2000Hz (also quite high load for such CPU).
Question is: is it possible to collect stream data without such high CPU load? How would you recommend to collect data over Ethernet to avoid high CPU load?
Hello,
We're investigating this now. Thanks for your patience.
I'm seeing similar results on a Raspberry Pi 2. At this point, there's no easy way to significantly decrease the CPU load for a given number of channels and scan rate. We can work on optimizing LJM, but I can't make any promises. What kind of CPU usage would be satisfactory to you?
We are going to collect data from more then 30 sensors. So we will have to use couple T7 boards in the system. 20% CPU load (10% per board for all 14 chnnels) would be fine. But I suppose it's not possible. I suppose all the CPU load is used to work with J7 protocol implementation. TCP iself doens't take that much CPU.
Anyway make a comment in this post if you will be able to improve CPU load. Thank you!
Out of curiosity, have you run a profiler to see what is using up the CPU when you are streaming?
No I have not. I used just "top" command to check CPU load. I have not run profiler to check what function call takes most of the CPU.
MOHOMAX, I've finally made progress on this. CPU usage for 14 AIN channels at 2000 Hz for my Pi2 was around 21%. Please try the new LJM 1.1200 beta installer.
Also, please accept my apologies for taking so long to figure this out. I was overthinking the problem.
Hi MOHOMAX, I'd like to bribe your forgiveness by offering you a free shirt or two.
If you want, pick your types and sizes: https://labjack.com/shirts
Then email/call/fax your details and we'll ship it to you (for free if you live in the US).
Hi,
You don't need forgiveness :). It's ok. I can't check new version of LJM because I am working on other tasks right now. Currently we are not going to use T7, but I will keep it in mind
Hi,
I have similar problems when using T7. CPU usage is too high and must be reduced. Momentary we are streaming two channels with sampling frequency 44100 Hz. Testing system is running on Linux (virtual environment). Two cores of CPU i5 have been assigned to virtual Linux system. CPU usage variates and after few seconds we get BUFFER OWERFLOW ERROR. For the project, we would like to use PC with dual core CPU and therefore we must limit CPU usage down to at most 20 %. We already uploaded and installed Beta drivers, but ljm.py returns error:
‘<class 'labjack.ljm.ljm.LJMError'>: Cannot load the LJM library libLabJackM.so. libLabJackM.so: cannot open shared object file: No such file or directory’.
Really weird, because all libraries are installed correctly. We also checked if files are in proper folders.
What is the output of the LJM installer and what is the output of the Python_LJM installer? Also, what is the output of the following commands?
If running the program using `sudo` works, you need to log out and log back in. You could also try running a plain C example program to see if the problem is specific to your Python_LJM installation.
It sounds like upgrading to LJM 1.1200 would fix your streaming problems but—for completeness—if you're still getting error 1301 (LJME_LJM_BUFFER_FULL), please read this link: https://labjack.com/support/software/api/ljm/streaming-lots-of-9999-values (recently edited).
Hi
/usr/local/lib
I can try with plain C code to see if its working.
BR
Hi Pinto, what is the output of uname -a? This is to make sure you are using the correct Linux download for your computer's architecture type.
Also, it looks like /usr/local/lib is probably set up correctly, but to make sure: what is the output of ls -l /usr/local/lib? (Note: the -l is important.)
Also, are your running your Python program as root?
Hi
yes I'm running Python as root on Linux Debian 8.5.
Output of ls -l /usr/local/lib:
lrwxrwxrwx 1 root staff 31 Oct 26 10:49 libLabJackM.so -> /usr/local/lib/libLabJackM.so.1
lrwxrwxrwx 1 root staff 36 Oct 26 10:49 libLabJackM.so.1 -> /usr/local/lib/libLabJackM.so.1.12.0
-rwxr-xr-x 1 root staff 2930980 Oct 26 10:49 libLabJackM.so.1.12.0
-rwxr-xr-x 1 root staff 3026352 Oct 17 17:46 libLabJackM.so.1.13.0
lrwxrwxrwx 1 root staff 37 Oct 26 10:49 liblabjackusb.so -> /usr/local/lib/liblabjackusb.so.2.5.3
-rwxr-xr-x 1 root staff 36917 Oct 26 10:49 liblabjackusb.so.2.5.3
drwxrwsr-x 4 root staff 4096 Oct 17 17:03 python2.7
Output of uname:
Linux
BR
That all looks ok so far. It sounds like there are two things that need to be checked. Either you have the wrong architecture type for libLabJackM, or Python_LJM is not installed correctly.
To check your architecture type: The following command will tell what architecture type your computer has:
uname -a
(The -a is important.) This gives me, for example, output like this:
Linux localhost.localdomain 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
The x86_64 is the architecture on this Linux machine in this example.
Sometimes uname -p can be used instead of uname -a. See man uname for details.
Once you know the architecture type of your computer, make sure you download the correct LJM installer. If you want to verify that you have the correct architecture type of libLabJackM installed, the following command may be used:
file /usr/local/lib/libLabJackM*
This gives me output that includes something like:
/usr/local/lib/libLabJackM.so.1.13.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
The x86-64 shows that it is correct for a x86_64 architecture.
To check your Python_LJM installation: Did running a plain C example work? If a plain C example works, we know Python_LJM is installed incorrectly and we can go from there.
Hi,
I confirm that with LJM 1.1200 beta stream mode works much better: we have 20% CPU load when streaming 14 AIN channels with sample rate 2 kHz.And 4% CPU load when streaming 2 AIN channels with sample rate 2 kHz
For that test we were using BeagleBone Black.
Hi,
Hardware:
- Raspberry PI 3 (armv71 kernel version 4.9.35-v7),
- Labjack T7
Software:
- LabJackM-1.1406-Raspbian-Linux-armhf.tar.gz (03/17/2017),
- gcc version 4.9.2
Task:
- Streaming 2 AIN with 45 kHz or only one AIN with90 kHz.
Problems:
- CPU usage 100 % and more (2 cores are used to stream of 4 available),
- More than 30 % of the scans were skipped.
Testing:
- Using stream_basic.c script from LabjackM/examples/stream/ folder,
- htop api on linux to check CPU usage.
Wish:
- No scans should be skipped while streaming with high speed,
- CPU usage should be much lower, let say 20 % when streaming with the highest speed.
BR
Please try using an Ethernet connection. I was able to get 0 skipped scans on a Raspberry Pi 3 with 2 AIN at 95 kHz this way, though CPU usage was still 50% (possibly 2 cores running at 100%).
Some additional tips can be found here: https://labjack.com/support/software/api/ljm/streaming-lots-of-9999-values
Scan rate = 45000 Hz, scanning 2 AIN, setting LJM_WriteLibraryConfigS(LJM_DEBUG_LOG_MODE, LJM_DEBUG_LOG_MODE_NEVER)
I try Ethernet connection (direct plug into PI) and also get 0 skipped scans. Problem after 594 scans:
deviceScanBacklog: 19, LJMScanBacklog: 899916
LJM_eStreamRead error: "LJME_LJM_BUFFER_FULL" (ErrorCode: 1301).
LJMScanBacklog increases all time until reaches LJM buffer overflow and CPU load is to high. Two cores are busy with streaming task and one of them in on 100%, what is not acceptable for us.
When reducing the scan rate to 22050 Hz, only one core was busy and CPU load was round 85%. deviceScanBacklog: 4, (average) LJMScanBacklog: 904. Probably there is no way to improve CPU load when using T7 with high sampling rates...?
I will investigate optimizing LJM's streaming code. I will update this thread.
LJM 1.1600 has improved CPU efficiency during stream. It is available here, currently in the beta installer, for armhf (ARMv7 with kernel 3.* or later):
https://labjack.com/support/software/installers/ljm
ARMv7 with kernel 2.* and ARMv6 will be released next week.