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

Add log about resource usages on slow threads #1885

Merged
merged 23 commits into from
Oct 8, 2024

Conversation

justinpersaud
Copy link
Contributor

@justinpersaud justinpersaud commented Oct 2, 2024

Details

We are trying to figure out what is causing high CPU usage in Bedrock for https://github.com/Expensify/Expensify/issues/417250

This PR adds a wrapper on the thread class that allows us to track the CPU time/CPU % any thread is using.

Fixed Issues

related to https://github.com/Expensify/Expensify/issues/417250

https://github.com/Expensify/Expensify/issues/433363

Tests

To test it locally, run the the test suite and confirm that you see logs like this logs:

2024-10-04T14:27:20.658325+00:00 expensidev2004 bedrock10007: xxxxxx (ResourceMonitorThread.cpp:19) after [socket3] [info] Thread finished. pID: '117844', CPUTime: '361µs', CPUPercentage: '79.691%'

Internal Testing Reminder: when changing bedrock, please compile auth against your new changes

@justinpersaud justinpersaud self-assigned this Oct 2, 2024
@danieldoglas danieldoglas self-assigned this Oct 3, 2024
Copy link

melvin-bot bot commented Oct 4, 2024

I see this code uses list. If your primary use case is just checking to see if an item exists in the list, perhaps set is a better choice, as it's much faster for random access. C++ has a variety of data structures available to choose from, so pick the best for your use case.

@danieldoglas danieldoglas changed the title Log new thread process IDs Add log about resource usages on slow threads Oct 4, 2024
Copy link
Contributor

@flodnv flodnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good 👍

static thread_local double cpuStartTime;

static void before();
static void after();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should pick a more descriptive name for these? It doesn't really matter that much to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to beforeProcessStart and afterProcessFinished. Let me know what you think

@danieldoglas
Copy link
Contributor

@tylerkaraszewski @flodnv updated, ready for re-review!

flodnv
flodnv previously approved these changes Oct 8, 2024
thread(ResourceMonitorThread::wrapper<F&&, Args&&...>, forward<F&&>(f), forward<Args&&>(args)...){};
private:
static uint64_t threadStartTime;
static double cpuStartTime;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are broken now, they should not be static, the values are shared between threads that way. These should just be member variables.

@tylerkaraszewski tylerkaraszewski merged commit 52ea542 into main Oct 8, 2024
1 check passed
@tylerkaraszewski tylerkaraszewski deleted the jpersaud_log_thread branch October 8, 2024 19:38
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