LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Text file appears to have gotten too large to write to it fast enough even with the file reference open between saves

Solved!
Go to solution

I have a program I'm developing where I write to a text file. There's a save time which queues an "Acquire" state for the consumer loop to handle. I've been testing the limits of the program before I hand it off to my coworker who will be operating it, and I've run into an issue that I'm having trouble tracking down the root cause.

 

The save timer is set to 1 second, so every second the consumer loop goes through its Acquire state and logs data to a text file which is kept open until the test is completed. I've been letting the program run for a few days at a time while keeping an eye on file sizes and the size of the queue as well. For a while everything seemed to be fine, and the file i/o actions didn't clog up the queue, but this morning I found that the queue had become backed up and was growing at a steady rate of one element per second. This suggested to me that there was a function somewhere in the code that was preventing an Acquire state from completing.

 

My thought is that the text file I'm writing to is getting too large. After a few days of writing to the file it gets to be a few 10,000 KB - upwards of 50,000. Since the write to file occurs every second, I elected to keep the file reference open instead of running the Open File VI and Close File VI every Acquire occurrence.

 

rseabeck_1-1687274905402.png

I've watched the queue size, and it never seemed to falter. And when it did falter it was overnight so I couldn't see what might have happened. I was under the impression that keeping the file reference open would help avoid issues, but was I wrong? Is there still a point where the file could get too large to handle even if it's already open? The files I'd been writing to were about 55,000 KB this morning, and since the queue size was steadily increasing I believe this is the size the file was when the program failed.

 

Let me know if there's any subVIs in the attached VI that you'd like to see.

0 Kudos
Message 1 of 13
(1,801 Views)

What I suspect happened is that after a few hours with no human around to send a "I'm still here, don't fall asleep!" signal, Windows decided to save some energy and entered "sleep" mode.

 

Either that or your hard drive is 99.44% full, and the system is busy shuffling the remaining Free Space around to make some room (I don't really think this is the issue ...).

 

Here's a suggestion.  Once a minute, write a TimeStamp (in text format) to a "Timer.csv" file.  Use Write Delimited Spreadsheet, and pass your single entry through a Build Array (to make the 1D Array that Write Delimited likes).  True, this will open/go to EOF/Write/close each time, but this should take a small fraction of a second.  And when you wake up, you can see when/if it stopped.

 

Do you have a cat?  Could it be "Kitten on the Keys"?

 

Bob Schor

0 Kudos
Message 2 of 13
(1,793 Views)

Thank you for the reply! I should have added more information, this is running on a cRIO 9045, so it has nothing to do with Windows. I no longer think that there's an issue with the file size - in fact I think that I have discovered the issue.

 

I have seen behavior before where there's a stretch of time on the XY plot that doesn't have data being written to it once per second. See below at 9:09 am.

rseabeck_0-1687370590869.png

 

I copied the XY plot data to my clipboard and moved that to Excel, and there were missing data points around 9:09. Then I went into the text file and checked around 9:09 am, and sure enough there were about 60 data points all at 9:09:58 am. This suggested to me that the queued-up Acquire states all unloaded in the span of a second (see following picture).

 

rseabeck_1-1687371846035.png

 

I thought it was odd that the XY plot writing loop and the consumer loops both got stalled, but the other loops in the program were working fine (queue size kept increasing which meant the save timer was working, front panel wasn't stuck on any particular tab, and indicators were updating normally), so I looked at the XY plot writing loop and the Acquire state of the consumer loops to see what they both shared in common. 

 

In both loops I have a subVI that pulls various data from several global variables. In the Acquire stat this subVI pulls the data and then sends it to the text file. In the XY plot writing loop it pulls the data that is sent to the XY plot. On a whim I checked the VI properties and noticed that in the context help for "Non-reentrant execution" it mentions that you should only use "Preallocated clone reentrant execution" on Real-Time targets. Since I'm using a cRIO I think that this means I need to go into all of my subVIs and set them all to Preallocated clone reentrant execution.

 

Based on some of the things I'm reading online, multiple calls to a Non-reentrant subVI can cause hangups in the loops they are being called at, and this agrees with the fact that only the loops with this subVI were stalled.

 

I appreciate you taking the time to reply to me! I'm going to try changing all of the subVIs that I have to Preallocated clone and see if that solves things.

0 Kudos
Message 3 of 13
(1,775 Views)

Subtle!  Two stars for you if that fixes the problem!

 

Bob Schor

0 Kudos
Message 4 of 13
(1,752 Views)

Back to say that even converting all my subVIs that are called multiple times did not fix the issue. I had the same thing occur where the queue got clogged up with a minute's worth of Acquire state messages.

 

The weird thing is that it's been exactly a minute's worth both times that I've caught it. 

 

rseabeck_0-1687378716250.png

 

rseabeck_1-1687378903879.png

 

 

0 Kudos
Message 5 of 13
(1,750 Views)

I'll add that the files had only been created 30 minutes before the problem came up this most recent time, so I think it's safe to say file size is not at fault.

0 Kudos
Message 6 of 13
(1,748 Views)

Are you using a LabVIEW Project file (.lvproj), with all (or almost all) of your created VIs saved inside a disk "physical" folder?  I think if you want more help, you will need to use "Send to:", "Compressed (zipped) folder" on the Project File and attach the resulting .zip file to a reply.

 

One catch -- many of the more experienced Forum users are using LabVIEW versions 2-4 years older than LabVIEW 2023, so you may need to "Save for Previous Version".  If you do this, it will create "earlier versions" of not only your Project Folder, but some elements of LabVIEW files, making a new "Project Folder" that contains versions of your Project + the LabVIEW Libraries.  Find the folder with your "Previous" LabVIEW Project and just compress that one folder.

 

Bob Schor

0 Kudos
Message 7 of 13
(1,716 Views)

Let me know if this works, I saved a 2019 version. To get to the .lvproj file go C > 1dm2 labview > CO2.lvproj

 

Sorry the file structure is all over the place...I didn't learn best practices till after I started this project and I was too far along to worry about fixing it lol....

0 Kudos
Message 8 of 13
(1,709 Views)

Made an interesting observation just now....could be coincidence, but could be something

 

So I'm running a remote front panel so that my coworker who I'm building this for can run the program without having the development software installed. Sometimes I will open the front panel and see this. It's just a matter of refreshing the page to open it up again. BUT I noticed a few times that the weird blip on the XY plot a couple comments up would have occurred shortly before losing the connection with the remote panel. I thought it was just a coincidence, and it could still be because I don't know if it's possible to force this to occur programmatically to check it, BUT it seemed like an interesting coincidence no less. Best I can do so far is put my computer to sleep for ~5 min and hope that when I come back to the remote panel it's been disconnected.

 

rseabeck_1-1687465805270.png

 

I'm going to fiddle around with the remote panel property invoke nodes to see if I can find a way to programmatically induce this connection loss and then see if this is what's causing the blip.

0 Kudos
Message 9 of 13
(1,688 Views)

EDIT Ignore this comment - spoke too soon, and need to play around more with the code

0 Kudos
Message 10 of 13
(1,682 Views)