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

HPCC-32108 Gather and report regex cache statistics #19193

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

dcamper
Copy link
Contributor

@dcamper dcamper commented Oct 11, 2024

This PR also opens up ISectionTimer so that other code can define and set nested statistics. In addition, a general type of "peak number/count" statistic has been defined.

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Cloud-compatibility
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Smoketest:

  • Send notifications about my Pull Request position in Smoketest queue.
  • Test my draft Pull Request.

Testing:

Manual test via workunit submission, staring at ECL Watch, and reviewing wutool output.

@dcamper dcamper requested review from ghalliday and shamser October 11, 2024 15:25
Copy link

Jira Issue: https://hpccsystems.atlassian.net//browse/HPCC-32108

Jirabot Action Result:
Workflow Transition To: Merge Pending
Updated PR

Copy link
Contributor

@shamser shamser left a comment

Choose a reason for hiding this comment

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

There are just a few minor suggestions.

@@ -20,34 +20,63 @@
#include "thorstats.hpp"
#include "jdebug.hpp"

// Available sets of statistics for a nested section
const StatisticsMapping defaultNestedSectionStatistics({StCycleLocalExecuteCycles, StTimeLocalExecute, StNumStarts, StNumStops});
const StatisticsMapping genericCacheNestedSectionStatistics({StCycleLocalExecuteCycles, StTimeLocalExecute, StNumStarts, StNumStops, StNumCacheAdds, StNumCacheHits, StNumPeakCacheObjects});
Copy link
Contributor

Choose a reason for hiding this comment

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

genericCacheNestedSectionStatistics should build on defaultNestedSectionStatistics so that if defaults are ever changed, the changes are reflected in genericCacheNestedSectionStatistics:

const StatisticsMapping genericCacheNestedSectionStatistics(defaultNestedSectionStatistics, {StNumCacheAdds, StNumCacheHits, StNumPeakCacheObjects})

Suggested change
const StatisticsMapping genericCacheNestedSectionStatistics({StCycleLocalExecuteCycles, StTimeLocalExecute, StNumStarts, StNumStops, StNumCacheAdds, StNumCacheHits, StNumPeakCacheObjects});
const StatisticsMapping genericCacheNestedSectionStatistics({StCycleLocalExecuteCycles, StTimeLocalExecute, StNumStarts, StNumStops, StNumCacheAdds, StNumCacheHits, StNumPeakCacheObjects});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Note that defaultNestedSectionStatistics is actually the last arg to the next constructor rather than the first.

}

unsigned __int64 ThorSectionTimer::getStartCycles()
{
starts.addAtomic(1);
nested.queryStatistic(StNumStarts).addAtomic(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

minor:

nested.addStatisticAtomic(StNumStarts, 1)

elapsed.addAtomic(delay);
stops.addAtomic(1);
nested.queryStatistic(StCycleLocalExecuteCycles).addAtomic(delay);
nested.queryStatistic(StNumStops).addAtomic(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: nested.addStatisticAtomic should be used.


void ThorSectionTimer::mergeStatistic(__int64 kind, unsigned __int64 value)
{
nested.queryStatistic(static_cast<StatisticKind>(kind)).merge(value, queryMergeMode(static_cast<StatisticKind>(kind)));
Copy link
Contributor

Choose a reason for hiding this comment

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

nested.mergeStatistic(static_cast(kind), value) should be used. MergeMode will be handled by CRuntimeStatistic


void ThorSectionTimer::setStatistic(__int64 kind, unsigned __int64 value)
{
nested.queryStatistic(static_cast<StatisticKind>(kind)).set(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: preferable to use nested.setStatistic()


void ThorSectionTimer::addStatistic(__int64 kind, unsigned __int64 value)
{
nested.queryStatistic(static_cast<StatisticKind>(kind)).addAtomic(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: preferable to use nested.addStatisticAtomic()

@@ -18828,7 +18828,16 @@ void HqlCppTranslator::buildTimerBase(BuildCtx & ctx, CHqlBoundExpr & boundTimer
HqlExprArray registerArgs;
registerArgs.append(*getSizetConstant(activityId));
registerArgs.append(*createConstant(name));
OwnedHqlExpr call = bindFunctionCall(registerTimerId, registerArgs);
OwnedHqlExpr call;
if (statsOption == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

clearer to

if (statsOption==ThorStatDefault)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but making ThorStatDefault visible would require including a header and I am loathe to do so at this point. I did add a comment here, nothing what the zero actually means. I can, of course, include the header and use the enum value name instead if you really think it is worth it; let me know.

ecl/hqlcpp/hqlhtcpp.cpp Show resolved Hide resolved
ecl/hqlcpp/hqlhtcpp.cpp Show resolved Hide resolved
@dcamper dcamper requested a review from shamser October 14, 2024 13:16
Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

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

@dcamper looks like a good change. A few minor comments (including those from Shamser), but looks like it is close to ready to merge.

StringAttr name;
CRuntimeStatisticCollection & nested;
Copy link
Member

Choose a reason for hiding this comment

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

picky: From this classes' point of view it is not nested, so "stats" would be a simpler/clearer name.

@@ -361,6 +361,20 @@ ISectionTimer * CActivityCodeContext::registerTimer(unsigned activityId, const c
return timer;
}

ISectionTimer * CActivityCodeContext::registerStatsTimer(unsigned activityId, const char * name, unsigned int statsOption)
Copy link
Member

Choose a reason for hiding this comment

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

cleanup: I would reimplement the function above by calling this with the default argument. Reduces code, and ensure the new function is tested in many existing situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. It was on my TODO and I missed it.

rtl/eclrtl/eclregex.cpp Show resolved Hide resolved
@@ -6127,7 +6129,9 @@ void HqlCppTranslator::doBuildCall(BuildCtx & ctx, const CHqlBoundTarget * tgt,
const char * name = str(external->queryId());
if (getStringValue(nameTemp, queryAttributeChild(external, timerAtom, 0)).length())
name = nameTemp;
buildHelperTimer(ctx, boundTimer, name);
// Grab optional ThorStatOption enum (as an int)
int statOption = getIntValue(queryAttributeChild(external, timerAtom, 1), 0);
Copy link
Member

Choose a reason for hiding this comment

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

type should be consistent with the call above (int v __int64)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -2147,6 +2147,18 @@ class CRoxieContextBase : implements IRoxieAgentContext, implements ICodeContext
}
return timer;
}
virtual ISectionTimer * registerStatsTimer(unsigned activityId, const char * name, unsigned int statsOption)
Copy link
Member

Choose a reason for hiding this comment

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

again (and in all other non-trivial occasions) worth re-implementing the old function by calling the new.

@dcamper
Copy link
Contributor Author

dcamper commented Oct 14, 2024

@ghalliday Changes made, please re-review. Thanks!

@dcamper dcamper requested a review from ghalliday October 14, 2024 15:56
Copy link
Contributor

@shamser shamser left a comment

Choose a reason for hiding this comment

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

Looks good.

@dcamper dcamper force-pushed the hpcc-32108-regex-cache-stats branch from 1685b28 to 4ec6e9b Compare October 15, 2024 20:50
@dcamper
Copy link
Contributor Author

dcamper commented Oct 15, 2024

Aside: Force-pushed an update to resolve a conflict when I rebased with the latest master branch updates.

Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

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

@dcamper looks good. A few final comments (which can be ignored). Please squash.

@@ -1309,6 +1316,18 @@ class CRoxieServerActivity : implements CInterfaceOf<IRoxieServerActivity>, impl
}
return timer;
}
virtual ISectionTimer *registerStatsTimer(unsigned activityId, const char * name, unsigned int statsOption)
{
CriticalBlock b(statscrit); // reuse statscrit to protect functionTimers - it will not be held concurrently
Copy link
Member

Choose a reason for hiding this comment

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

trivial: another case where the old could call the new

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argh. I missed that one. Thanks for catching it.

rtl/eclrtl/eclregex.cpp Show resolved Hide resolved
@dcamper dcamper force-pushed the hpcc-32108-regex-cache-stats branch from 4ec6e9b to fde7031 Compare October 16, 2024 12:04
@dcamper
Copy link
Contributor Author

dcamper commented Oct 16, 2024

@ghalliday Squashed. Thanks!

Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

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

@dcamper see comment

@@ -20,34 +20,63 @@
#include "thorstats.hpp"
#include "jdebug.hpp"

// Available sets of statistics for a nested section
const StatisticsMapping defaultNestedSectionStatistics({StCycleLocalExecuteCycles, StTimeLocalExecute, StNumStarts, StNumStops});
const StatisticsMapping genericCacheNestedSectionStatistics({StNumCacheHits, StNumPeakCacheObjects}, defaultNestedSectionStatistics);
Copy link
Member

Choose a reason for hiding this comment

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

Missing StNumCacheAdds...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@dcamper dcamper force-pushed the hpcc-32108-regex-cache-stats branch from fde7031 to 0f6e244 Compare October 16, 2024 14:05
@ghalliday ghalliday merged commit 474e817 into hpcc-systems:master Oct 16, 2024
51 of 52 checks passed
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.

3 participants