|
PowerBASIC Forums
![]() Programming
![]() Process Memory Info
|
| next newest topic | next oldest topic |
| Author | Topic: Process Memory Info |
|
Michael Mattias Member |
I have a client for whom I developed an application which reads and reformats a data file. Pseudo-code: Load File Data to single dynamic string. File contains variable length delimited records.
Save modified array to fixed-record-length file. In the Fixup routines, Array() is never resized. When the files were the size originally specified, (10-30 Mb), no problem. But due to increased business, files are now in the 60-80 Mb range, and when this program runs customer says system performance is degraded. This is an NT Server running lots of jobs all day long. We "think" the performance hit is due to the large dynamic allocation of memory. Program obviously allocates (filesize) bytes to load the file data, plus approximately (filesize) bytes to hold the array into which the file is parsed. And while I recently changed to allocate an approximate number of elements for the array 'as soon as possible' (that is, when the file is first loaded), it is possible that at some point during the program run I need to do a REDIM PRESERVE ARRAY(currentsize + more space), which means for a brief moment the RAM requirement is (filesize) + (2 * ArraySize) ... with a 70 Mb input file, about 210 Mb! We "think" we want to try to reduce the dynamic allocation requirement by using disk instead of RAM, but before we make the investment in this change (not really that much, maybe a half day. Will change to use memory-mapped file object for input, and fixed-length random-access work file for fixup routines), we want to get some idea of the actual usage of RAM by the program. So.... I found the PSAPI WinAPi functions, especially GetProcessMemoryInfo(), which looks like it returns the info we want.. or at least, as close as we're going to get on a 'live' system. GetProcessMemoryInfo returns this structure:
I've been thru the SDK a couple of times, and still can't figure out which of these numbers - if any - are the numbers which tell us "yes, this change has / has not reduced the dynamic allocation requirements of this application." I have to believe those "peak" members are the key values, but I'm not sure. Can anyone point me to a good reference, or explain which numbers are important? I'm going to report everything just before end of job. I just don't know which of those numbers is meaningful. Thanks, ------------------ IP: Logged |
|
Michael Mattias Member |
If I may ask a favor?? Since I use Win/98, I was unable to test this on a machine where it should work.. Could people with Win NT, Win2K and Win Xp please test this on those O/S's please? If it works out, I think this will produce something useful for everyone... Thanks,
IP: Logged |
|
John Revill Member |
Windows 2000 Server, Service Pack 4, 512 MB
------------------ [This message has been edited by John Revill (edited January 11, 2004).] IP: Logged |
|
Michael Mattias Member |
Thank you... so it "appears" that I didn't do anything totally dopey... But now it becomes obvious from the statistics that I should have put in some memory allocation function to look at Peak v Current So what if we make the PbMain function look like this...
Thanks, IP: Logged |
|
Steve Matthews Member |
(compiled with #debug error on, #register none) [This message has been edited by Steve Matthews (edited January 11, 2004).] IP: Logged |
|
Raymond King Member |
Michael, What about using a Memory map file you think that would help? Enjoy ------------------ http://www.csdsoft.com IP: Logged |
|
Michael Mattias Member |
Aha! So it looks like Windows sends the big allocation directly to the swap file instead of sucking up current RAM.. actually makes sense, since we never modified any of the 50 Mb we allocated. This is going to be a fun thing to see what happens when I change the "real" application.... >What about using a Memory map file you think that would help? That is exactly what I am planning. But I wanted to get this 'report memory statistics' thing working first, so we have a reasonable "before" picture. (I am putting the statistics thing in the existing software, and client will run it against "big file" keep the numbers.) How I am going to change the application is... The rest of the code remains the same. I should have "before" and "after" info with "live" data later this week. This should be very interesting! (I'll also clean up the above demo and post it in the source code section so others can find it and use it. MCM IP: Logged |
|
Michael Mattias Member |
Bravely, he posted the actual 'before' figures from the Real Live Customer system (Windows/2000) ...knowing full well if his proposed change doesn't do anything dramatic he's going to look like a dope...
IP: Logged |
|
Michael Mattias Member |
Cleaned up demo, tested only PB/Windows but should work as is with PB/CC: http://www.powerbasic.com/support/forums/Forum7/HTML/002201.html MCM IP: Logged |
|
Paul Dwyer Member |
Michael, can't you stream the file so that you don't put so much data in memory? what happens if the file is a Gig or just too big to keep in memory some time in the future. Since it happened once sure it can happen again? If the records require processing 'vertically' then it might be a problem but otherwise wouldn't it scale better (and hog less resources on this busy box) by reading say 100 records, processing them and then reading 100 more etc etc? This application seems like each function does it's job once them passes the buck, perhaps a more flowing approach would work better? sort of depends on what "fixupX" does I suppose ------------------ IP: Logged |
|
Michael Mattias Member |
>can't you stream the file ... Actually, yes, I could have... well, if not 'streamed' I could parse part of the file, process it, and continue with the next part of the file. But as I pointed out, when the file sizes were "as advertised" I did not see any need to do so. As far as the 'passing the buck' to multiple 'fixup' function things... IP: Logged |
|
Michael Mattias Member |
Client ran the revised program, same input file... here are the results Stats for the revised program:
Still not really sure what this means.. However, I am sure that when customer said,"this is fantastic!" whatever it means is good. IP: Logged |
All times are EasternTime (US) | next newest topic | next oldest topic |
![]() |
|
Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.