lifeemotions / knx.net

KNX.net provides a KNX API for .NET
MIT License
101 stars 47 forks source link

Speed up actions #39

Open christianhubmann opened 6 years ago

christianhubmann commented 6 years ago

I really like this library and it seems to be very well written. But I noticed that sending actions is kind of slow. Digging around the code in KnxLockManager.cs I found that PerformLockedOperation does a Thread.Sleep(200).

How did you come up with this value? I tried 50 and even 20 and it still works on my installation. Is this required by the KNX spec?

abelsilva commented 6 years ago

That Thread.Sleep(200) happens after you send the action

Now, if you send multiple actions that Sleep will have an impact

The reason it exists is because while working with multiple KNX IP Interfaces and Routers we noticed a lot of actions were being discarded when we ran scenarios with multiple actions at the same time (e.g.: turning off all lights) With the Sleep, the actions would take more time but would work

I'll add a parameter in the library to adjust (or disable) this behaviour so it can be possible to test without the delay

abelsilva commented 6 years ago

can you try version 1.1.10?

You will be able to do this:

var connection = new KnxConnectionTunneling("10.0.250.20", 3671, "10.0.253.5", 3671) { Debug = false };
connection.SetLockIntervalMs(0);
FalcoGer commented 6 years ago

I didn't know it would sleep. I implemented my own sleep between actions. Maybe this should be documented somewhere.