xiangfu0 commented on code in PR #18980:
URL: https://github.com/apache/pinot/pull/18980#discussion_r3571341432


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/BasePartitionUpsertMetadataManager.java:
##########
@@ -388,20 +388,27 @@ protected void doAddSegment(ImmutableSegmentImpl segment) 
{
 
     // Update metrics
     long numPrimaryKeys = getNumPrimaryKeys();
-    updatePrimaryKeyGauge(numPrimaryKeys);
+    updatePrimaryKeyGauge(numPrimaryKeys, getPrimaryKeyMapSizeInBytes());
     _logger.info("Finished adding segment: {} in {}ms, current primary key 
count: {}", segmentName,
         System.currentTimeMillis() - startTimeMs, numPrimaryKeys);
   }
 
   protected abstract long getNumPrimaryKeys();
 
-  protected void updatePrimaryKeyGauge(long numPrimaryKeys) {
+  /**
+   * Returns the estimated size in bytes of the primary-key-to-record-location 
map.
+   */
+  protected abstract long getPrimaryKeyMapSizeInBytes();
+
+  protected void updatePrimaryKeyGauge(long numPrimaryKeys, long 
primaryKeySizeInBytes) {
     _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId, 
ServerGauge.UPSERT_PRIMARY_KEYS_COUNT,
         numPrimaryKeys);
+    _serverMetrics.setValueOfPartitionGauge(_tableNameWithType, _partitionId,
+        ServerGauge.UPSERT_PRIMARY_KEY_MAP_SIZE_IN_BYTES, 
primaryKeySizeInBytes);
   }
 
   protected void updatePrimaryKeyGauge() {
-    updatePrimaryKeyGauge(getNumPrimaryKeys());
+    updatePrimaryKeyGauge(getNumPrimaryKeys(), getPrimaryKeyMapSizeInBytes());

Review Comment:
   `updatePrimaryKeyGauge()` is still called from the realtime `doAddRecord()` 
paths, so this now runs `getPrimaryKeyMapSizeInBytes()` for every ingested 
upsert record. That samples up to 1000 keys and calls `PrimaryKey.asBytes()` 
while Pinot is on the per-record ingestion path, adding bounded but repeated 
map iteration/allocation to a hot path. Please keep the per-record update 
count-only and refresh the byte-size gauge from segment lifecycle, a 
rate-limited path, or background sampling instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to