S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.3k stars 581 forks source link

S7: Huge DataBlock vs DataBlock multiplying. #419

Closed bolt-b closed 2 years ago

bolt-b commented 2 years ago

Hello, In Step we can create relatively big data blocks and read them in our applicaions by means s7net library. Is there any experience in terms how does affect on reading time a data block containing e.g. 160 bytes? And how do affect on reading time five data blocks each containing 32 bytes? Both are providing the same data volume. What do you think? Any thoughts? Will be there a difference in time?

Thanks in advance

Jason-Jelks commented 2 years ago

This really will depend on the PLC processor, the architecture of your process and how often you need to read / write to the data blocks. I work with datablocks that range from 2 bytes to well over 5700 bytes total, however I don't need 100% of the data block with each read. If I need to access data near real-time such as encoder value I will typically create independent and minimal UDT which your class can mirror a UDT which you can then set as an array T[ ]. It is up to you whether you read independent UDT or the full DB with multiple UDT. But this follows SRP (Single Responsibility Principle) and can be more tedious to setup, especially if you don't control the PLC logic.

For the sizes you are talking about the difference will be negligible unless the CPU is under load.

From a practical standpoint; for our process we have taken it a bit further, which is currently in my branch (which you are welcome too use); but we have modified the S7.net Class structures, as our processes communicate using gRPC (primarily streaming) which allows us to provide real-time data for 11 DataBlocks, supporting 8 motion axis, which comes to 88 independent read/write UDT's which are from 8x2 (16-bytes) (bit/flag processes) up to 8x714 (5712-bytes). I have not done any benchmarking to test, but I do know there is a marked reduction when you go over the max PDU size (960 for S7-1200 & S7-1500). which is another reason why we break down our DataBlocks into smaller defined UDT. For what its worth, we use S7-1200 and S7-1500 Safety PLC. 95% of our calls are using the [S7.net Class] calls, as opposed to ReadByte(Async). There is a bit of speed improvement if you can exclusively write Bytes without having to parse, but that can also make extensibility more complex in the future.

Hope this is helpful.

scamille commented 2 years ago

If you read/write the same amount of bytes (smaller in total than the max PDU size) in smaller chunks compared to in a big one, there definitely will be overhead. The S7 protocol has header structure, S7.NET needs to build/parse those requests, there can (with some exceptions) usually be only a single requests active so you can't run those chunks concurrently, and also the PLC itself needs to do more work. The biggest factor in all this will be the network latency for all this overhead.

So I would definitely recommend reading as much data as you can/need from a datablock in a single call. Yyou can even read multiple data blocks in a single request. If you have multiple independent consumers of that data you can always design something to give them only the relevant slice/view of the data they require.