BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MM B&V - ManyThreadsTest
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Ivo Tops
Guest





PostPosted: Sat Feb 19, 2005 10:18 am    Post subject: MM B&V - ManyThreadsTest Reply with quote



The MM B&V tool should really have a test that uses over a 100 threads.
Several server applications at my work use a couple of hundred threads
so the number is not unrealistic. During our selection of a memory
manager we found out some MM's are not equipped for that amount of threads.

I know for certain that MultiMM has two crashing bugs of which one is
very likely to show up only after you reach a 100 threads.

I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors? <big smile>

Kind regards,

Ivo Tops
Back to top
Pierre le Riche
Guest





PostPosted: Sat Feb 19, 2005 11:42 am    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote



Hi Ivo,

Quote:
I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors?

You are more than welcome. The idea is to try and bring out weaknesses in
your opponents' entries.

Regards,
Pierre



Back to top
Pierre le Riche
Guest





PostPosted: Sat Feb 19, 2005 11:54 am    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote



Hi Again,

Quote:
I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors?

I have two suggestions for you multithreaded tests:
a) a test that allocates a 252 byte block, immediately reallocs it to 1
byte and does this a million times in a loop (using many theads if you
like).
b) a test that allocates a 1 byte block, immeditely reallocates it to 13
bytes and does this a million times in a loop (using threads again if you
like).

*evil grin*

Regards,
Pierre



Back to top
Robert Houdart
Guest





PostPosted: Sat Feb 19, 2005 12:11 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

"Ivo Tops" wrote in message...
Quote:
The MM B&V tool should really have a test that uses over a 100 threads.

I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors?

Ivo,

1) Eric's "transient threaded objects" benchmark (TWildThreads) already uses
96 threads. Easiest would be to increase the thread count in that benchmark
from 96 to 128.

2) The more biased the better... As long as everybody's goal is to have
some sensible tests to finally get the best possible MM, that's OK. You
learn more from a benchmark in which your MM performs badly than from one in
which it excels.

Robert



Back to top
Martin James
Guest





PostPosted: Sat Feb 19, 2005 12:15 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Quote:

I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors?
I have two suggestions for you multithreaded tests:
a) a test that allocates a 252 byte block, immediately reallocs it to 1
byte and does this a million times in a loop (using many theads if you
like).
b) a test that allocates a 1 byte block, immeditely reallocates it to 13
bytes and does this a million times in a loop (using threads again if you
like).


c) Creates (number of processors) threads with real-time priority that
allocate & dellocate a memory block around an auto-reset event wait call.
Have a timer fire this event occasionally to make all these threads ready at
once.

Rgds,
Martin



Back to top
Robert Houdart
Guest





PostPosted: Sat Feb 19, 2005 12:23 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hi Pierre,
Please, no more reallocation benchmarks Smile
And if you really want more, I would prefer them slightly more "real-world".

As said before, I do not care about winning the contest, I simply want us to
finish with the very best MM. It would be foolish to adapt some of the
parameters in our respective MM to perform better in farfetched benchmarks,
but less well in real-world applications. That would beat the whole purpose
of the challenge...

Robert


Quote:
Hi Again,

I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors?
I have two suggestions for you multithreaded tests:
a) a test that allocates a 252 byte block, immediately reallocs it to 1
byte and does this a million times in a loop (using many theads if you
like).
b) a test that allocates a 1 byte block, immeditely reallocates it to 13
bytes and does this a million times in a loop (using threads again if you
like).

*evil grin*

Regards,
Pierre



Back to top
Fredrik Lysholm
Guest





PostPosted: Sat Feb 19, 2005 1:04 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

I agree.. if this is something you feel some MMs would fail then I'd rather
see it as a part of the validation..

Just another crazy idea... I've noticed that some MMs perform worse after a
while.. why not add a set of "pre-benchmark" functions that tries to
screw-up the MM? The mentioned re-allocation tests in a multithread
enviroment could quallify as one of those.. (or simply always require the
benchmark to run ones before we actully start counting..)

// Fredrik


"Robert Houdart" <robert (AT) elinksuite (DOT) com> wrote

Quote:
Hi Pierre,
Please, no more reallocation benchmarks Smile
And if you really want more, I would prefer them slightly more
"real-world".

As said before, I do not care about winning the contest, I simply want us
to finish with the very best MM. It would be foolish to adapt some of the
parameters in our respective MM to perform better in farfetched
benchmarks, but less well in real-world applications. That would beat the
whole purpose of the challenge...

Robert


Hi Again,

I don't mind writing the test, but are additions in code to the tool
accepted from biased memory manager authors?
I have two suggestions for you multithreaded tests:
a) a test that allocates a 252 byte block, immediately reallocs it to 1
byte and does this a million times in a loop (using many theads if you
like).
b) a test that allocates a 1 byte block, immeditely reallocates it to 13
bytes and does this a million times in a loop (using threads again if you
like).

*evil grin*

Regards,
Pierre





Back to top
Pierre le Riche
Guest





PostPosted: Sat Feb 19, 2005 1:44 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hi Robert,

Quote:
finish with the very best MM. It would be foolish to adapt some of the
parameters in our respective MM to perform better in farfetched
benchmarks, but less well in real-world applications. That would beat the
whole purpose of the challenge...

I agree, that's why I suggested those benchmarks. While never downsizing
blocks of less than 256 bytes in size and excessive block upsizing on
realloc does very well on some of the current benchmarks, I feel it is not
appropriate for real-world apps.

Regards,
Pierre




Back to top
Robert Houdart
Guest





PostPosted: Sat Feb 19, 2005 2:57 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hello Pierre,

I'm glad to have the opportunity to explain the background of the choices in
BucketMM. Sorry for the length of the answer...

First of all, for the benefit of others less familiar with BucketMM, let me
explain what BucketMM does:
1) if you upsize a block smaller than 256 bytes, it will upsize by at least
64 bytes
2) it never downsizes blocks smaller than 256 bytes

A crucial question is: when does Delphi perform downsizing/upsizing of
blocks smaller than 256 bytes ? IME this is nearly always related to string
manipulation.

Most Delphi developers tend to be rather careless about string
manipulations. They're not aware that in the following loop they call the
Realloc function 256 times:

aString:='';
for j := 1 to 256 do
aString := aString + 'A';

This is poorly performing code. Much better is:

SetLength(aString, 256);
for j := 1 to 256 do
aString[j] := 'A';

with just a single call to GetMem and performance maybe 100 times better
than the previous with the standard RTL MM.

The goal of BucketMM is to reduce the performance penalty for the first
code.
In fact, with BucketMM you get pretty close to the pre-Delphi 4 situation
with static ShortStrings of 256 bytes instead of AnsiStrings. So you combine
the reference-counted AnsiStrings with the pre-Delphi 4 performance of the
ShortStrings.
Furthermore, most dynamically constructed strings are rather short-lived, so
the memory overhead remains fully acceptable.

I feel that in most real-world applications made by Delphi developers, the
BucketMM choices are very sound, improving the performance and having little
impact on the overall memory consumption.
On the other hand, I have difficulty in seeing how you could, in a normal
Delphi application, come close to a situation in which systematically a
252-byte block is allocated and then downsized to 1 byte, or, a 1-byte block
is allocated and then upsized to 13 bytes.
Of course, the BucketMM parameters could easily be adapted to this kind of
benchmark, but if this situation never happens in a normal Delphi
application, what's the point ?

If you feel BucketMM is taking undue advantage of this feature in the
benchmark results, you're absolutely right. There are too many realloc
benchmarks, and I try to remedy the situation by adding non-realloc
benchmarks and starting a hopefully long series of Replay Benchmarks. If we
end up with between 10 and 20 replay benchmarks on real applications, they
will clearly tell us which approach is best.

In the meanwhile, you might consider adopting the same strategy in FastMM.
It would be interesting to see the results of that...

Kind regards,
Robert


Back to top
Martin James
Guest





PostPosted: Sat Feb 19, 2005 5:06 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Quote:

First of all, for the benefit of others less familiar with BucketMM, let
me
explain what BucketMM does:
1) if you upsize a block smaller than 256 bytes, it will upsize by at
least
64 bytes
2) it never downsizes blocks smaller than 256 bytes

Sounds reasonable to me. In fact, I would tend to be even more liberal, I
have been known to shift the block size by 2, ie *4, in some
buffer-managers, after all, as you point out, the buffer will probably be
deallocated in short order & so available for re-use.

Adding half-as-much-again sounds like a good compromise between memory waste
and performance in a general-purpose memory manager.

Quote:
A crucial question is: when does Delphi perform downsizing/upsizing of
blocks smaller than 256 bytes ? IME this is nearly always related to
string
manipulation.

Yes - yuk.

Quote:
Most Delphi developers tend to be rather careless about string
manipulations. They're not aware that in the following loop they call the
Realloc function 256 times:

aString:='';
for j := 1 to 256 do
aString := aString + 'A';

This is poorly performing code. Much better is:

SetLength(aString, 256);
for j := 1 to 256 do
aString[j] := 'A';

with just a single call to GetMem and performance maybe 100 times better
than the previous with the standard RTL MM.

Delphi long string policy has always been an anoyance to me. Presumably,
those 256 reallocs could be accompanied by 256 critical-section
acquire/releases, with some chance that one or more may require a kernel
call because of contention.

I have maintained for some time that Delphi needs a non-ref-counted
long-string type that has an initial size and has the option of
auto-resizing on overflow, (realloc), or allowing an exception to be raised.
One of the reasons for this is poor string expansion management.

Quote:
The goal of BucketMM is to reduce the performance penalty for the first
code.
In fact, with BucketMM you get pretty close to the pre-Delphi 4 situation
with static ShortStrings of 256 bytes instead of AnsiStrings. So you
combine
the reference-counted AnsiStrings with the pre-Delphi 4 performance of the
ShortStrings.

Good :)

Quote:

If you feel BucketMM is taking undue advantage of this feature in the
benchmark results, you're absolutely right.

IMHO, this feature is taking advantage of real application design. Adding
one char to a string is an operation that is needed so often that it sucks
that frequent anything should be required.

Rgds,
Martin





Back to top
Pierre le Riche
Guest





PostPosted: Sat Feb 19, 2005 6:56 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hi Robert,

Quote:
A crucial question is: when does Delphi perform downsizing/upsizing of
blocks smaller than 256 bytes ? IME this is nearly always related to
string manipulation.

I can think of a few instances in my own programs where this is not the
case. In my own virtual treeview objects, for example, every node has a list
of child nodes (maintained by a pointer to memory, a current child node
count and a current child node capacity). In my code I already manage the
buffer size intelligently to avoid unnecessary reallocs. Any extra padding
performed by the MM just wastes memory.

Quote:
If you feel BucketMM is taking undue advantage of this feature in the
benchmark results, you're absolutely right. There are too many realloc
benchmarks, and I try to remedy the situation by adding non-realloc
benchmarks and starting a hopefully long series of Replay Benchmarks. If
we end up with between 10 and 20 replay benchmarks on real applications,
they will clearly tell us which approach is best.

The problem with replay benchmarks is that they will have to be short to
keep file sizes reasonable. What about the long term effects? If you have a
situation where you frequently reallocate small blocks (like in my virtual
tree objects) eventually they'll all end up 256 bytes in size.

Quote:
In the meanwhile, you might consider adopting the same strategy in FastMM.
It would be interesting to see the results of that...

All my MMs pad upsizes and try to avoid downsizing, but so far I've been a
bit more conservative: I don't downsize blocks smaller than 32 bytes and I
pad by 25% on upsize - irrespective of block size. If I change that to 256
and 25% + 64 bytes respectively I get a speed boost of about 7% in the Nexus
single-threaded test.

Regards,
Pierre



Back to top
Robert Houdart
Guest





PostPosted: Sun Feb 20, 2005 12:19 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hello Pierre,

Your answer clearly illustrates the point that it may not be possible to
find a single MM that will prove the very best for each and every
application.

The virtual treeview is a good example of small block resizing that is not
related to string manipulations, I now understand your benchmark much
better. For this case, the BucketMM settings will indeed have you using more
memory than would really be required.

On the other hand, the performance improvement on the NexusDB benchmarks
shows you something which is also quite real-world. I do expect a lot of
Delphi applications to contain some awkward string construction code that
benefit from the BucketMM settings.

So what's the right balance ?
We could both very easily implement the choice of downsize limit of 32 or
256 bytes and upsize increase of 25% or 25% + 64 bytes by means of a
conditional define.
Problem is we're going to end up with a bunch of compiler directives that
nobody will ever use for the simple reason they would not be aware of the
issue.

Could we provide the MM with some intelligence of its own to adapt its
behaviour to the demands ?
One idea is to store a realloc count for each memory block. As long as the
realloc count is smaller than, say, 4, the MM could return the exact number
of bytes. Above that point, the MM might add some intelligence to anticipate
future reallocations.

Thanks for the discussion,
Robert


Back to top
Robert Houdart
Guest





PostPosted: Tue Feb 22, 2005 8:45 am    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Quote:
One idea is to store a realloc count for each memory block. As long as the
realloc count is smaller than, say, 4, the MM could return the exact
number of bytes. Above that point, the MM might add some intelligence to
anticipate future reallocations.

I've implemented this approach in BucketMem 1.4.
A memory chunk that is reallocated less than EXACT_REALLOC_COUNT times
always gets the exact requested size.
If the chunk is reallocated more often, the MM anticipates future demands by
upsizing more and downsizing less that is really required.

Robert



Back to top
Pierre le Riche
Guest





PostPosted: Tue Feb 22, 2005 6:55 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hi Robert,

Quote:
I've implemented this approach in BucketMem 1.4.
A memory chunk that is reallocated less than EXACT_REALLOC_COUNT times
always gets the exact requested size.
If the chunk is reallocated more often, the MM anticipates future demands
by upsizing more and downsizing less that is really required.

I don't see how this change improves the situation. Whether a block is
resized once or resized a million times, the MM should always behave
responsibly and not use 256 bytes if a 1 byte block would have been
sufficient.

I am sorry but this seems like a very contrived "optimization" aimed
squarely at the B&V benchmarks: What it does is boost scores in the NexusDB
benchmarks (it upsizes strings many times, so the padding mechanism kicks in
and you avoid further reallocs after realloc no.2), while tricking the block
resize benchmarks into thinking that BucketMem doesn't pad reallocs (because
they don't realloc enough to trigger the padding mechanism).

All I have to do now is change the realloc benchmarks to reallocate
EXACT_REALLOC_COUNT times and we're back to where we were.

Regards,
Pierre



Back to top
Robert Houdart
Guest





PostPosted: Tue Feb 22, 2005 8:47 pm    Post subject: Re: MM B&V - ManyThreadsTest Reply with quote

Hello Pierre,

1) Please read Martin James's reply on my original post. He strongly agrees
that the 256 byte downsize feature aims at a design flaw of the Delphi
AnsiString implementation. I have literally seen hundreds of code examples
of people both inside and outside my company to know that this issue is
real.

2) Once again, I'm more interested in real-world applications than in the
benchmarks.
I made the ReallocCount development because it seemed like an original idea
that might give some improvement for real-world applications. It was btw
triggered by our discussion.
At this point it's an experimental feature of which I hope it will make a
difference in some of the replay benchmarks. If it does not, it will
probably disappear. On the other hand, if it does improve performance on the
real-world replays, surely we should keep it ?
Ultimately it's the real-world applications that will decide, not the small
virtual world of MM benchmarks. So if everybody helps to get some real-world
replay benchmarks, we will soon have better arguments to evaluate new
features...

3) Please feel free to adopt the same ideas/techniques/algorithms.
Everything is open-source, plainly visible to everybody. If some
ideas/techniques are bad, our benchmarks should tell us ! If some are good,
likewise !

4) If you do not feel happy with the NexusDB Benchmark, let's change it so
it is no longer a reallocation benchmark and no longer relies so heavily on
System.Move.

5) Please feel free to adapt your benchmark in the way you describe.

6) I do not share the philisophy that our goal should be to expose
weaknesses in other MM's. The danger is that one creates benchmarks that
have no significance outside the little theatre of the Fastcode challenge.
I prefer to create benchmarks with the focus on similarity with real
applications. If the MM happens to perform badly, great, it's an opportunity
to learn and to improve the algorithm. This was initially the case with my
own "Raw Performance" benchmarks, which has learned me a lot.

Kind regards,
Robert


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.