On 1 June 2010 15:57, Mike Caron <[email protected]> wrote:
> On 31/05/2010 11:44 PM, Ralph Versteegen wrote:
>>
>> On 31 May 2010 11:58, Ralph Versteegen<[email protected]>  wrote:
>>>
>>> On 31 May 2010 10:20, Mike Caron<[email protected]>  wrote:
>>>>
>>>> On 30/05/2010 6:01 PM, Ralph Versteegen wrote:
>>>>>
>>>>> On 31 May 2010 08:57, Mike Caron<[email protected]>    wrote:
>>>>>>
>>>>>> D:\ohrrpgce>dir gentest.xml
>>>>>> 30/05/2010  04:52 AM       237,804,960 gentest.xml
>>>>>>
>>>>>> D:\ohrrpgce>xml2reload gentest.xml gentest.rld
>>>>>> Loaded XML document in 20857 ms
>>>>>> Memory usage: 301
>>>>>> Parsed XML document in 17049 ms
>>>>>> Memory usage: 573142499
>>>>>> Freed XML document in 35378 ms
>>>>>> Optimised document in 31149 ms
>>>>>> Memory usage: 428328275
>>>>>> Serialized document in 8557 ms
>>>>>> Tore down memory in 173 ms
>>>>>> Finished in 116510 ms
>>>>>>
>>>>>> D:\ohrrpgce>dir gentest.rld
>>>>>> 30/05/2010  04:31 PM       203,271,865 gentest.rld
>>>>>>
>>>>>> And, here's a profile of CPU and Memory usage while doing the above:
>>>>>>
>>>>>> http://taleotc.com/Reloadprofile.png
>>>>>>
>>>>>> Note that on the CPU graph, Green is Usermode, while Red is Kernel
>>>>>> mode.
>>>>>> And
>>>>>> that my CPU thinks it's dual core, so you should consider the 50% mark
>>>>>> to
>>>>>> be
>>>>>> "max".
>>>>>
>>>>> Hyperthreading?
>>>>
>>>> Aka, "Make applications think the CPU can multiple things at once, when
>>>> in
>>>> reality it can't!". I guess "Hyperthreading" is more marketable, though.
>>>> :)
>>>>
>>>>>> Further, you should care more about the "Commit" memory, rather than
>>>>>> th
>>>>>> "Physical" memory.
>>>>>> --
>>>>>> Mike
>>>>>
>>>>> Yikes! Nearly twice as long to free as to load the XML document. Looks
>>>>> like the memory allocator thrashed a lot while freeing memory, which
>>>>> is odd because I would have expected xml nodes to be deleted in about
>>>>> the same order they were created. Maybe libxml deletes attribute nodes
>>>>> after deleting children. (Yes! I checked, and my hunch is correct!)
>>>>>
>>>>> I assume that 3.0GB marks the total virtual memory committed on the
>>>>> machine, and xml2relaod used roughly 1.5GB?
>>>>
>>>> Yes, that's correct.
>>>>
>>>>> What does that xml file look like? It's interesting that the resulting
>>>>> .reld is nearly the same size as the original! That 64MB test case
>>>>> compressed to half the size.
>>>>
>>>> I used this program to generate a document:
>>>>
>>>> http://www.xml-benchmark.org/downloads.html
>>>>
>>>> It seems to have a lot of content in the form of text nodes. Alas, I
>>>> can't
>>>> find the place I got the original document, since it was basically more
>>>> of
>>>> the same.
>>>>
>>>> I suppose we could just cat the 64-meg document to itself, and do a tiny
>>>> bit
>>>> of editing :D
>>>>
>>>>> Serialisation could be a bit faster (you can always increase the
>>>>> buffer size to speed it up, going from 32kb to 64kb caused about a 20%
>>>>> improvement), but mostly I'm happy with that.
>>>>
>>>> Honestly, that's the least of my concerns. That's always going to scale
>>>> linearly with the resulting document size.
>>>>
>>>> I'm more concerned, now, with the thing we haven't really been
>>>> profiling:
>>>> Loading these stupidly large documents again. I modified reloadtest to
>>>> load
>>>> it, and it ain't pretty:
>>>
>>> Well, I told you to profile them, and have been doing so myself; who
>>> cares how long it takes to convert an XML?
>>>
>>> And speaking of profiling, I tried profiling but got totally useless
>>> results missing nearly all running time.
>>>
>>>> Test #19: loadHugeDocument... Pass
>>>> Took 50 s
>>>> Test #20: freeHugeDocument... Pass
>>>> Took 297 ms
>>>>
>>>> And, just for completion's sake, here's the 64 Meg-document's RELOAD:
>>>>
>>>> Test #19: loadHugeDocument... Pass
>>>> Took 19 s
>>>> Test #20: freeHugeDocument... Pass
>>>> Took 53 ms
>>>>
>>>> Ouch.
>>>
>>> What the devil? Here are my times, after warming up of course, on
>>> windows XP this time, with a private heap:
>>>
>>>> reload2reload medline.reld medline2.reld
>>>
>>> Loaded document in 12743 ms
>>> Serialized document in 1062 ms
>>> Tore down memory in 17 ms
>>> Finished in 13824 ms
>>>
>>> But!!!!! here's what it was in linux (back then the buffer was
>>> smaller, I think now the serialization time is about 2.5s):
>>>
>>> bash-3.1$ time reload2reload medline2.reld medline2_.reld
>>> Loaded document in 3724 ms
>>> Serialized document in 3506 ms
>>> Tore down memory in 597 ms
>>> Finished in 7838 ms
>>>
>>> real    0m7.892s
>>> user    0m5.276s
>>> sys     0m0.440s
>>>
>>> So, it looks like Linux is being way too paranoid about flushing the
>>> file to disk as its written, or something like that (there are so many
>>> options in the kernel for tuning file systems; looks like they're not
>>> set for performance in this case on my machine), and conversely
>>> Windows is doing something REALLY stupid when loading it in. I mean,
>>> the reload file is read in a linear manner, what on earth could the
>>> problem be? Argh! We may have to write a file buffering layer for
>>> reading files as well! Or maybe the problem is in allocating nodes?
>>> We could test this by loading the file into memory before attempting
>>> to load it.
>>
>> OK, I tested and confirmed that file reads are the problem. I loaded
>> the whole file into memory and then read from that ("inmem"). Then I
>> also added an arena allocator, which allocates 2MB at a time and doles
>> it out, and used it to allocate memory for new Nodes ("arena").
>> Finally I tried allocating strings for string nodes with the arena as
>> well ("strings"), which we couldn't do in practice:
>>
>> medline.reld load time (each warmed up with several runs):
>>
>> Windows/NTFS, private heap:
>> Initial (current SVN):  12743 ms
>> inmem: 2658ms
>> inmem+arena: 1422ms
>>
>> Linux/ext3:
>> Initial (current SVN):  3603 ms
>> arena: 3018ms
>> inmem: 2263ms
>> inmem+arena: 1588ms
>> inmem+arena+strings: 1431ms
>>
>> Time to delete on Linux: 480ms without and 250ms with the arena;
>> negligible on Windows.
>>
>> Serialisation time (near-equal in all of above): 1200ms
>>
>> So to solve the load time problem on windows I could write a buffer
>> binary file input abstraction as well. But what's the point? Why not
>> just memmap the whole file in when loading? The in-memory size of the
>> RELOAD tree is going to be much larger than the file, so you're not
>> reducing memory requirements by much by messing around with a fixed
>> size buffer. On the other hand, if you're not loading in the whole
>> file (delayed loading), that's probably going to demand a different
>> buffering design, so once again, we shouldn't waste time writing it
>> right now.
>
> The thing about delay loading is that it might be, say, twice as slow, but
> that will be acceptable because it's only doing a tiny bit of work at a
> time.
>
> That said, in cases where delay loading would be unwanted (save games, etc),
> we should still use the memory mapped file approach. The nice thing about
> memory mapped files is that even if you map a 500 meg file, it won't load it
> until you actually ask for the pages.

Which may mean memmapping is fine when delay loading too. Might be OS dependent.

> Actually, thinking about this, I wish I'd thought about this earlier, since
> it would make a lot of the loading code easier.

So, who's going to implement it?

>>> Also, on Linux it took less than half as long to delete the document
>>> as it does in Windows without a private heap.
>>>
>>>> One thing I want to implement is allocating memory for multiple nodes at
>>>> once. This will be tricky, though, since deleting nodes is a problem.
>>>> Hmm...
>>>> I will give this some thought...
>>>
>>> I don't think that's really necessary (unless the memory allocation
>>> really is the bottleneck) and would be pretty damn messy.
>>
>> I misunderstood you; thought you were talking about that rtlArray
>> stuff. Allocating multiple nodes at once is not very complex or messy.
>> And I think not being able to free blocks of memory as nodes are
>> deleted would not be too large a problem: in which circumstances would
>> you actually be doing a lot of deleting? I can't think of many aside
>> from the optimise step in xml2reload, and the others would only occur
>> in Custom, not Game, where I think it won't be a problem.
>>
>> However, by looking at the numbers above, it looks like it would
>> reduce load time by 25% at most, not worth it.
>
> Well, my idea would only be useful when loading a tree from disk, not
> building it in RAM (how does it know how many nodes you're going to add
> here?).
>
> Last night, I tried implementing it with a "read only" option, so it would
> disallow modifying the (very fragile) tree, but it ended up getting so
> complicated that I'd have to rewrite quite a bit of stuff, which I didn't
> feel like doing.
>
> I think we should just forget this particular idea and move on.

Oh, I guess I didn't misunderstand, seems you were thinking about
rltArray. I meant writing a simple memory allocator which allocates
space for multiple Nodes at a time (say 64, which is 4kB) but also
allows freeing Nodes: it keeps a free list and deletes chunks if they
become totally empty. I've written exactly this before. Anyway.

> --
> Mike
> _______________________________________________
> Ohrrpgce mailing list
> [email protected]
> http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org
>
_______________________________________________
Ohrrpgce mailing list
[email protected]
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org

Reply via email to