Lora-net / sx1302_hal

SX1302/SX1303 Hardware Abstraction Layer and Tools (packet forwarder...)
Other
219 stars 272 forks source link

High CPU load when using the packet forwarder #40

Closed yamo-goe closed 3 years ago

yamo-goe commented 3 years ago

I am using an SX1302 corecell module with this library and packet forwarder on a custom system. Unfortunately the current configuration of the packet forwarder uses a whole lot of CPU time on that system. I was able to narrow it down to the JIT queue thread and uplink thread, they both use much of the CPU time relative to the available resources of the system. I was able to lower the CPU load by adjusting the parameter of the wait_ms(...) function-call in the respective threads from 10ms to 100ms. Is there a reason that these sleep times for the threads were chosen so low? Is it safe to just change the wait times in those thread without any compatibility issues? Having these parameters adjustable over the global_conf.json would be very helpful in a future version.

Thanks and regards

mcoracin commented 3 years ago

Hello, The JIT thread is responsible for regularly checking if there is a downlink to be programmed in the sx1302 based on its current internal time. It checks if the departure time is "soon" compared to the current time, using the TX_JIT_DELAY value as margin. If you lower the wait_ms() un thread_jit, maybe you should increase the value of TX_JIT_DELAY too. To Maybe 100 or 200ms. We put this value as low, to be as reactive as possible.

Concerning the thread_up(), I guess that you refer to wait_ms(FETCH_SLEEP_MS); FETCH_SLEEP_MS can be increased if needed, it is just that depending on the load you have, the sx1301 RX buffer may get filled earlier. But if your system is not too loaded, it should be quite safe.

Remember that the packet_forwarder is given as an example, then you are free to tweak it according to your needs and constraints.

Best regards