DBZ-3756 Add UGA/PGA memory statistics to JMX metrics

This commit is contained in:
Chris Cranford 2021-07-15 15:07:01 -04:00 committed by Chris Cranford
parent 52e198e3b5
commit d450f58b37
4 changed files with 98 additions and 0 deletions

View File

@ -367,6 +367,18 @@ public String getTableMetadataDdl(TableId tableId) throws SQLException {
}
}
/**
* Get the current connection's session statistic by name.
*
* @param name the name of the statistic to be fetched, must not be {@code null}
* @return the session statistic value, never {@code null}
* @throws SQLException if an exception occurred obtaining the session statistic value
*/
public Long getSessionStatisticByName(String name) throws SQLException {
return queryAndMap("SELECT VALUE FROM v$statname n, v$mystat m WHERE n.name='" + name +
"' AND n.statistic#=m.statistic#", rs -> rs.next() ? rs.getLong(1) : 0L);
}
public static String connectionString(Configuration config) {
return config.getString(URL) != null ? config.getString(URL)
: ConnectorAdapter.parse(config.getString("connection.adapter")).getConnectionUrl();

View File

@ -90,6 +90,10 @@ public class OracleStreamingChangeEventSourceMetrics extends StreamingChangeEven
private final AtomicReference<Scn> committedScn = new AtomicReference<>();
private final AtomicReference<Scn> offsetScn = new AtomicReference<>();
private final AtomicInteger unparsableDdlCount = new AtomicInteger();
private final AtomicLong miningSessionUserGlobalAreaMemory = new AtomicLong();
private final AtomicLong miningSessionUserGlobalAreaMaxMemory = new AtomicLong();
private final AtomicLong miningSessionProcessGlobalAreaMemory = new AtomicLong();
private final AtomicLong miningSessionProcessGlobalAreaMaxMemory = new AtomicLong();
// Constants for sliding window algorithm
private final int batchSizeMin;
@ -177,6 +181,10 @@ public void reset() {
minBatchProcessingTime.set(Duration.ZERO);
maxBatchProcessingTime.set(Duration.ZERO);
totalResultSetNextTime.set(Duration.ZERO);
miningSessionUserGlobalAreaMemory.set(0L);
miningSessionUserGlobalAreaMaxMemory.set(0L);
miningSessionProcessGlobalAreaMemory.set(0L);
miningSessionProcessGlobalAreaMaxMemory.set(0L);
// transactional buffer metrics
lagFromTheSourceDuration.set(Duration.ZERO);
@ -576,6 +584,26 @@ public int getUnparsableDdlCount() {
return unparsableDdlCount.get();
}
@Override
public long getMiningSessionUserGlobalAreaMemoryInBytes() {
return miningSessionUserGlobalAreaMemory.get();
}
@Override
public long getMiningSessionUserGlobalAreaMaxMemoryInBytes() {
return miningSessionUserGlobalAreaMaxMemory.get();
}
@Override
public long getMiningSessionProcessGlobalAreaMemoryInBytes() {
return miningSessionProcessGlobalAreaMemory.get();
}
@Override
public long getMiningSessionProcessGlobalAreaMaxMemoryInBytes() {
return miningSessionProcessGlobalAreaMaxMemory.get();
}
public void setOldestScn(Scn scn) {
oldestScn.set(scn);
}
@ -676,6 +704,20 @@ public void incrementUnparsableDdlCount() {
unparsableDdlCount.incrementAndGet();
}
public void setUserGlobalAreaMemory(long ugaMemory, long ugaMaxMemory) {
miningSessionUserGlobalAreaMemory.set(ugaMemory);
if (ugaMaxMemory > miningSessionUserGlobalAreaMaxMemory.get()) {
miningSessionUserGlobalAreaMaxMemory.set(ugaMaxMemory);
}
}
public void setProcessGlobalAreaMemory(long pgaMemory, long pgaMaxMemory) {
miningSessionProcessGlobalAreaMemory.set(pgaMemory);
if (pgaMemory > miningSessionProcessGlobalAreaMaxMemory.get()) {
miningSessionProcessGlobalAreaMaxMemory.set(pgaMemory);
}
}
@Override
public String toString() {
return "OracleStreamingChangeEventSourceMetrics{" +
@ -735,6 +777,10 @@ public String toString() {
", warningCount=" + warningCount.get() +
", scnFreezeCount=" + scnFreezeCount.get() +
", unparsableDdlCount=" + unparsableDdlCount.get() +
", miningSessionUserGlobalAreaMemory=" + miningSessionUserGlobalAreaMemory.get() +
", miningSessionUserGlobalAreaMaxMemory=" + miningSessionUserGlobalAreaMaxMemory.get() +
", miningSessionProcessGlobalAreaMemory=" + miningSessionProcessGlobalAreaMemory.get() +
", miningSessionProcessGlobalAreaMaxMemory=" + miningSessionProcessGlobalAreaMaxMemory.get() +
'}';
}
}

View File

@ -294,6 +294,26 @@ public interface OracleStreamingChangeEventSourceMetricsMXBean extends Streaming
*/
int getUnparsableDdlCount();
/**
* @return the current mining session's UGA memory usage in bytes.
*/
long getMiningSessionUserGlobalAreaMemoryInBytes();
/**
* @return the current mining session's UGA maximum memory usage in bytes.
*/
long getMiningSessionUserGlobalAreaMaxMemoryInBytes();
/**
* @return the current mining session's PGA memory usage in bytes.
*/
long getMiningSessionProcessGlobalAreaMemoryInBytes();
/**
* @return the current mining session's PGA maximum memory usage in bytes.
*/
long getMiningSessionProcessGlobalAreaMaxMemoryInBytes();
/**
* Resets metrics.
*/

View File

@ -25,6 +25,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
@ -191,6 +192,8 @@ public void execute(ChangeEventSourceContext context, OraclePartition partition,
}
}
captureSessionMemoryStatistics(jdbcConnection);
streamingMetrics.setCurrentBatchProcessingTime(Duration.between(start, Instant.now()));
pauseBetweenMiningSessions();
}
@ -208,6 +211,23 @@ public void execute(ChangeEventSourceContext context, OraclePartition partition,
}
}
private void captureSessionMemoryStatistics(OracleConnection connection) throws SQLException {
long sessionUserGlobalAreaMemory = connection.getSessionStatisticByName("session uga memory");
long sessionUserGlobalAreaMaxMemory = connection.getSessionStatisticByName("session uga memory max");
streamingMetrics.setUserGlobalAreaMemory(sessionUserGlobalAreaMemory, sessionUserGlobalAreaMaxMemory);
long sessionProcessGlobalAreaMemory = connection.getSessionStatisticByName("session pga memory");
long sessionProcessGlobalAreaMaxMemory = connection.getSessionStatisticByName("session pga memory max");
streamingMetrics.setProcessGlobalAreaMemory(sessionProcessGlobalAreaMemory, sessionProcessGlobalAreaMaxMemory);
final DecimalFormat format = new DecimalFormat("#.##");
LOGGER.info("Oracle Session UGA {}MB (max = {}MB), PGA {}MB (max = {}MB)",
format.format(sessionUserGlobalAreaMemory / 1024.f / 1024.f),
format.format(sessionUserGlobalAreaMaxMemory / 1024.f / 1024.f),
format.format(sessionProcessGlobalAreaMemory / 1024.f / 1024.f),
format.format(sessionProcessGlobalAreaMaxMemory / 1024.f / 1024.f));
}
private void abandonOldTransactionsIfExist(OracleConnection connection, OracleOffsetContext offsetContext, TransactionalBuffer transactionalBuffer) {
Duration transactionRetention = connectorConfig.getLogMiningTransactionRetention();
if (!Duration.ZERO.equals(transactionRetention)) {