LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid datasocket overhead?

Solved!
Go to solution

I am writing to PSP Shared Variables and  I want to use datasocket writes so I can do it programatically with arrays of clusters, with each cluster containing both the data to be writen and and the Shared Variable names (6 values and 6 Shared Variables per array element at this time). My overall architecture is a state machine with 4 states, and one of the states has a For Loop that goes through the array and writes all the data from the clusters. This works fine but is too slow, so I have been looking into the timing of the datasocket writes. I put a single write into a loop and the time for 100, 1000 and 10000 iterations was almost the same. It seems that there  is significant overhead associated with the first write, and that successive writes go much faster. This is demonstrated in the vi snippet attached below, where there are two For Loops that produce the same result. The first one has twice as many reads as the second, but executes ~50 times faster on my system (40 msec versus 1100 msec)! The reasons seems to be that the overhead associated with setting up the connection is only paid the first iteration for this method, while it is paid every iteration for the second method. Without knowing about this  overhead I would have picked the second method to be faster because it has half the number of reads.

 

The question I have now is how to optimize datasocket performance in the context of a more complex program? How can  I arrange things so that I only pay the timing overhead once?

0 Kudos
Message 1 of 2
(2,223 Views)
Solution
Accepted by topic author Richard2950

I would always explicitly call the Open DataSocket Connection function outside the loop first for any PSP variables you might write to. That forces the connection to be opened once and maintained.

 

If you're using LV2009 there's a new set of functions for dynamically writing to or reading from Shared Variables that should have much better performance than the DataSocket functions, and the API is very similar and easy to use.

Jarrod S.
National Instruments
0 Kudos
Message 2 of 2
(2,219 Views)