Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a max memory usage monitor #410

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ryanheath
Copy link

@ryanheath ryanheath commented Jul 31, 2023

Added support to monitor the bot's memory usage. Trying to solve #396

Since the framework does not natively support calculation of memory usage of a single object,
I used reflection to calculate the size of each reachable object through MyBot.
Depending on the memory structures used, it can be quite slow (reflection).

The remaining time is not affected for the other bot (EvilBot).

Also, "cheaters" can still access static objects that are not contained within MyBot. Those won't be factored into the memory usage.

Initially I wanted to have two stacked bars, but the height of the board has too many hard code values here and there.
So I split the bar in two :)

image

@DrBrask
Copy link

DrBrask commented Jul 31, 2023

I really like this idea but this thing is super slow.

If I add this one line to MyBot:

public (int, int)[] table = new (int, int)[1];

The call to ObjectSizeHelper.GetSize(..) takes more than 20 secs on my machine.

This is bad enough in itself but this call counts as time spend by the bot so it quickly times out...

@ryanheath
Copy link
Author

@DrBrask I have a workaround for the tuples, also the timer should not include the calculation time anymore.
Is it still slow for you? 20sec is waaay to slow, I see fractions of seconds when calculating the memory usage.

- stop the clock when calculating the memory usage
@ryanheath ryanheath force-pushed the feature/monitor-memory-usage branch from a7c68ff to d632013 Compare July 31, 2023 22:40
@DrBrask
Copy link

DrBrask commented Aug 1, 2023

That's much better!

ObjectSizeHelper.GetSize(..) never got above 4ms in 20 games or so.

For development I think this is useful.

For competition however I think a better setup, is to compile each MyBot class as separate UCI compliant program and run the two bot players as separate processes, measuring their memory usage, subtracting the baseline memory usage of the simplest possible bot.

@0qln
Copy link

0qln commented Aug 1, 2023

Hey, very cool what you did there! Is this for version 1.18? Alright is just downloaded is and it looks like it is, thanks!

@GediminasMasaitis
Copy link

GediminasMasaitis commented Aug 2, 2023

I would assume the memory limit is for the process, not for the bot-specific code, I recommend just using Process.PrivateMemorySize64.

@ryanheath
Copy link
Author

Not necessarily, unless we could run the different bots in their own process space,
memory sizes contain everything. You would not be able to determine the memory usage of a specific bot when you run both bots in the same process.

Another thing I've noticed is that memory usage can vary from game to game, so I keep track of the maximum memory size used.

VitorA29 added a commit to VitorA29/Chess-Challenge that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants