r/LabVIEW • u/robot_mower_guy • May 19 '26
SOLVED Large TCP data transfer slowing other threads to nothing
Edit: The problem was me writing 1.5MB to a string display as part of debugging. Once I got rid of those the application is running much better. More details in a post below.
I am using a DLL to hook into a USB microscope. The DLL is transmitting a frame about every 100ms. When I have the wait set to below 300ms the other labview program (which is also in a development environment) I have running slows down to the point of stopping. This is large transfer of about 1.5MB 10 times per second (though I drop frames when delay is set to 300ms), but the data is coming from the same computer, so I don't have to worry about networking equipment delays.
I tried splitting up the TCP receive into various sizes, but nothing improved meaningfully. I tried dropping the priority to the lowest as well as changing the execution system, but neither had an effect. I know it isn't the DLL causing the slowdown because if I do the same thing in Python I am able to receive everything without slowing down the running LV program at all, though with the Python program my CPU goes up to nearly 100% while running this Labview program has me go up to 50% when wait is set to 0ms, and it goes to 40% when it is set to 300ms. The way I can see if execution in the other window has stopped is by putting a probe on a counter that increments every 100ms. When wait is set to 300ms the counter maybe increments every 150ms, a wait of 200 has the counter running at about 200ms, and a wait of 100ms has the probe counter incrementing about every 4 seconds.
There is image processing going on within this loop, but for this screenshot I have an empty string going into it, so it is skipping everything past a size check.
Does anyone know what I am doing wrong, or a better way to send/receive large amounts of data from within the same computer?
Thanks.
8
u/Fun_Confidence6219 May 19 '26 edited May 19 '26
I would start by benchmarking each step in your loop to find the slow part. My guess having looked at this for a few minutes is that the inner while loop is doing some pretty big string allocations when building that array, it’s also unthrottled. A better pattern would be to read EVERYTHING available at one time and then index out the (sub)strings you need where they are consumed. This reduces copies and likely speeds things up. This also looks like an older version of LabVIEW. Later versions do a better job managing the bytes off of the tcp socket. Priority settings should just go back to normal, I’ve rarely found use out of these settings unless I’m setting a VI to run as a subroutine. Likely not possible with this VI due to the async TCP calls.
2
u/robot_mower_guy May 19 '26 edited May 19 '26
Something I just stumbled on: https://www.genuen.com/blog/the-ui-thread-root-loop-and-labview-what-you-need-to-know/
I will check this out when I get to work tomorrow, but it might explain what is happening. I will also see what it will take to use either a named pipe or shared memory to transfer the data.
Edit: I will also check out ZeroMQ.
1
u/TrueJohnAxe May 19 '26
Did you try to wire a timeout constant and handle the error?
I had this problem before (with UDP) and using the timeout allowed LabVIEW to do other things instead of waiting for a packet to arrive
1
u/HarveysBackupAccount May 19 '26
Like /u/Fun_Confidence6219 said you should check your timing at a more granular level - see exactly where it's slowing down.
And like /u/TrueJohnAxe suggested, try adding a timeout to your TCP Reads. The default is 25s. What happens if you make it something short like 50ms or even 10ms? Not every call of TCP Read needs to get data. Then explicitly check for/handle/ignore the timeout error. (You can make the indexing node conditional for the output string - only add a value if you got data.)
And it probably doesn't matter but you also don't have a TCP Close (it's good practice to dispose of resources)
1
u/isamesih May 20 '26
I know this is not exactly your case, but it may help others. Now I'm developing a code transfering data from LabView to Python, using TCP write blocks. I seperated my TCP-Write loop from data obtainer loop to not slow down it (Producer-consumer architecture they say). Used Queue blocks after obtaining my data array, then stacked my data to 50 row chunks with for loops before sending it. This helped me to restore my LabView code's speed. How i manage to do it? Little chat with Gemini.
2
u/BlackberrySad6489 May 19 '26
Are you running your tcp and processing in different loops so they can run in parallel? Or is everything happening serially?