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

Fix/fix json stats report #5831

Merged
merged 8 commits into from
Jun 19, 2023
Merged

Fix/fix json stats report #5831

merged 8 commits into from
Jun 19, 2023

Conversation

LukaszRozmej
Copy link
Member

@LukaszRozmej LukaszRozmej commented Jun 19, 2023

Changes

  • locks JsonRpcLocalStats.BuildReport to avoid conflicts between threads
  • Moves as much JSON RPC reporting to background, to avoid blocking JSON RPC execution times, if there is lock contention
  • Moves _divider to static variable, avoiding allocating it each time.
  • Caches and reuses StringBuilder avoiding allocating it each time.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Testing in app logs

methodStats ??= _currentStats.GetOrAdd(report.Method, _ => new MethodStats());
allTimeMethodStats ??= _allTimeStats.GetOrAdd(report.Method, _ => new MethodStats());
// we don't want to block RPC calls any longer than required
return Task.Run(() =>
Copy link
Member

Choose a reason for hiding this comment

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

Could just use

await Task.Yield();

To flip to the threadpool at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

But why?

Copy link
Member

Choose a reason for hiding this comment

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

Don't need to have a lambda sub method in the method; can just use that and make method async rather than Task.Run

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok but why would that be better? I don't have async code here (just sync code I want to fire&forget and do in the background), so introducing async code just to do Yield seems odd.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with Luk here

Copy link
Member

Choose a reason for hiding this comment

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

so introducing async code just to do Yield seems odd.

You've already done all that though? So the additional code for the yield is actually less code: 0a821a3 (delta change) + removing the added indentation from Task.Run

Copy link
Member Author

Choose a reason for hiding this comment

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

so introducing async code just to do Yield seems odd.

You've already done all that though? So the additional code for the yield is actually less code: 0a821a3 (delta change) + removing the added indentation from Task.Run

I introduced tasks, but no state machines, no reentrancy. await would be completely artificial.

methodStats ??= _currentStats.GetOrAdd(report.Method, _ => new MethodStats());
allTimeMethodStats ??= _allTimeStats.GetOrAdd(report.Method, _ => new MethodStats());
// we don't want to block RPC calls any longer than required
return Task.Run(() =>
Copy link
Contributor

Choose a reason for hiding this comment

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

agree with Luk here

@LukaszRozmej LukaszRozmej merged commit e39fd6a into master Jun 19, 2023
61 checks passed
@LukaszRozmej LukaszRozmej deleted the fix/fix_json_stats_report branch June 19, 2023 21:49
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.

None yet

3 participants