Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"640K ought to be enough for anybody" Sys(3050) best practices revisited 1

Status
Not open for further replies.

Olaf Doschke

Programmer
Oct 13, 2004
14,847
DE
There has been much discussion about what settings to make with SYS(3050). Perhaps the highest truth is "you can find the best value by trial and error".

First here is a good source of info with links to further discussion in the wiki:

This is rather a story and a correction to another statement I made about the SYS(3050) function in previous posts. I once said you could set this to a low value, like 1-8MB, and foxpro would higher the RAM allocation when needed. That's not the full truth, as it seems. Reading the wiki it states what is surely more correct:

wiki said:
SYS(3050) does not really affect "the memory available to Visual FoxPro", it only affects the memory used for things like caching tables and indexes.

So here I am taking back waht I said.

By the way, just as a side note... Bill Gates never said that quote about the 640KB. You find the full story behind it in wikiquotes. It just fits this topic as title, quite nice.


Let's see what problem I was faced and how I found out SYS(3050) would rescue me: For a few days a certain query on a large table (600MB) ran very slow. There was no error, not even a "not enogh memory to finish the operation" or something like that. Debugging did point us to some false positives, thinking about index corruption and other things. Finally I started up Rushmore optimisation reporting via SYS(3054,12) and it reported back "Not enough memory for optimization".

As said this is not raising an error, it simply leads to letting VFP run the query unoptimized, which is deadly for the performance of a query on a 500MB table.

I could solve that problem by highering memory buffers in the starting prg. There was a setting of it to 1MB. It seems the table has grown just enough to make that 1MB too less caching memory for indexes and highering it solved the problem.

I make one conclusions from this: The memory needed for caching is never raised by VFP on it's own, you need to adjust the setting yourself.

In my case the dbf as said has a size of 600MB, CDX file is about 200MB. As 8MB buffer memoery is sufficient, VFP only buffers partial DBF/CDX. That's also what is to be expected, but it would be good to know what amount of memory you need for rushmore to always work even on 500MB tables. I think what takes a few more bytes in memory is the "bitmap" it builds to determine the recnos it will retrieve That bitmap grows with the size of the table. The number of records is the main figure, I think. That bitmap should need 1bit per record (1 to denote to read the corresponding record, 0 for not needing that record). The 600MB DBF contains roughly 6.2 million records and this means a bitmap initially blank to fill in from rushmore with recnos read from index nodes, needs 6.2 million/8 bytes = 0.78 MB. That would take most of the 1MB buffer memory and if there are further things cached, of course this will make rushmore fail to get that .78 MB for it's rushmore bitmap.

Perhaps that's a good figure to think about, when determining SYS(3050) memory allocation size. Take the largest table you have in number of records and divide that by 8. Take into account joins with other tables, so add their reccount to the figure. Add a few KB to MB for other caching and you have a reasonable figure. I guess if whatever you get that way is lower than a MB, take at least a MB. I think the time is over to make it a percentage of the whole RAM, just think in absolute figures. The buffer you reserve is notfor code, the runtime itself, variables or such things. I have another application, where I move data of a few databases together and there I set the buffer to 500MB, which may not even be needed.

Finally, I want to point to
Christof Wollenhaupt said:
Even though it's true that you have full control over the page pool this is only half the truth as far as memory consumption is concerned. If Visual FoxPro is of the opinion it needs more memory, for instance, to store an optimization bitmap, then it doesn't hesitate to create temporary files if the page pool is not sufficiently large. FoxPro continues to run, even if the SYS(3050) value you specified is too low, eventually with the same speed, maybe slower, or even faster. This depends on what kind of memory is assigned to Visual FoxPro and which drive is faster.

I can't confirm, that Foxpro decides to allocate more memory or creates page files to store a new optimization bitmap, it simply does not and executes a query nonoptimised at least in some cases, so you better watch out for your setting.

Bye, Olaf.
 
Thanks for that, Olaf. It's very useful (and thanks to Christof too).

By the way, there's plenty of evidence for Bill Gates not making that "ought to be enough" remark. Similarly with his supposed statement about the Internet being a passing fad.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
To add after further readong of Christof: SYS(3050) really is just a max amount of memory VFP will allocate for it's caching of data and indexes and rushmore bitmaps. It's seperate from memory for objects/code/variables.

Also as another quote:
Christof said:
You can control the maximum size of this memory area separately for foreground and background processing. That means depending on whether the user is working with your application or not you can tell Visual FoxPro to use less or more memory. That memory is not allocated immediately but is allocated as needed. You can specify a huge value without having to fear that this amount of memory is immediately gone.

This means you can even set this to a quite high value without already taking away that memory from other processes or applications and this also means it's a max VFP really respects, even if it would be better to allocate more memory.

A good estimate for the value should take into account what you need at max, not at min and what you think you can get as physical RAM, not virtual swap file memory, even in the long run.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top