raspberry node-hid-stream:使用多个 hid 设备会减慢应用程序的执行速度

raspberry node-hid-stream: using multiple hid devices slowing down execution of application

我正在基于网络服务器在 Raspberry PI 4 1GB RAM 上构建一个应用程序,使用 express、node-hid-stream 和 serialport 库从 hid 设备和串行端口读取数据。使用 3 个 hid 设备一切正常,但在添加第四个设备应用程序后速度非常慢(在 5-10 分钟内启动 Web 服务器,串行端口甚至没有打开)。在具有 3 个和 4 个 hid 设备的 运行 应用程序期间,Raspberry RAM 消耗约为 700MB,只有应用程序滞后,所有 hid 设备的数据可用。
根据 node-hid 文档:

This is not a limitation of node-hid but a limitation of all user-space libraries. This is a security feature of the OS to prevent input device snooping.

也许这是个问题。

一些代码示例:

var express = require('express');
var socket = require('socket.io');
var app = express();
var server = app.listen(8080, function(){
    console.log('listening on port 8080');
    });
app.use(express.static('public'));

//Socket setup
var io = socket(server);

io.on('connection', function(socket){
    console.log('made socket connection')
    });

(...)

var serialport = require ("serialport");
var port = new serialport('/dev/ttyACM0', {
  baudRate: 9600,
   dataBits: 8,
   parity: 'none',
   stopBits: 1,
   flowControl: false,

});

port.on("open", function () {
  //console.log('port otwarty'); 
 port.on('data', function(data) {
    //console.log('data received: ' + data);
    f_CReaderCard(data.toString());
  });
});

(...)

var KeyboardCharacters = require('node-hid-stream').KeyboardCharacters;
var CReaderD1 = new KeyboardCharacters({path: '/dev/hidraw0'}); 
var CReaderD2 = new KeyboardCharacters({path: '/dev/hidraw1'}); 
var CReaderU1 = new KeyboardCharacters({path: '/dev/hidraw2'}); 
var CReaderU2 = new KeyboardCharacters({path: '/dev/hidraw3'}); 

(...)

通过在顶部添加此行来增加线程数

process.env.UV_THREADPOOL_SIZE=10

这会将环境变量 UV_THREADPOOL_SIZE 设置为 10

默认值为“4”,最大值为 1024