Skip to content

Commit

Permalink
Prometheus timers for ycsb
Browse files Browse the repository at this point in the history
  • Loading branch information
ctring committed Nov 17, 2023
1 parent cad6df7 commit 9b9ae0b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package com.oltpbenchmark.benchmarks.ycsb.procedures;

import com.oltpbenchmark.PrometheusMetrics;
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;

import io.prometheus.client.Histogram.Timer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -28,12 +31,15 @@

public class DeleteRecord extends Procedure {
public final SQLStmt deleteStmt = new SQLStmt(
"DELETE FROM " + TABLE_NAME + " where YCSB_KEY=?"
);
"DELETE FROM " + TABLE_NAME + " where YCSB_KEY=?");

//FIXME: The value in ysqb is a byteiterator
// FIXME: The value in ysqb is a byteiterator
public void run(Connection conn, int keyname) throws SQLException {
try (PreparedStatement stmt = this.getPreparedStatement(conn, deleteStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"delete").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, deleteStmt)) {
stmt.setInt(1, keyname);
stmt.executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package com.oltpbenchmark.benchmarks.ycsb.procedures;

import com.oltpbenchmark.PrometheusMetrics;
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;

import io.prometheus.client.Histogram.Timer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -28,12 +31,15 @@

public class InsertRecord extends Procedure {
public final SQLStmt insertStmt = new SQLStmt(
"INSERT INTO " + TABLE_NAME + " VALUES (?,?,?,?,?,?,?,?,?,?,?)"
);
"INSERT INTO " + TABLE_NAME + " VALUES (?,?,?,?,?,?,?,?,?,?,?)");

// FIXME: The value in ysqb is a byteiterator
public void run(Connection conn, int keyname, String[] vals) throws SQLException {
try (PreparedStatement stmt = this.getPreparedStatement(conn, this.insertStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"insert").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, this.insertStmt)) {
stmt.setInt(1, keyname);
for (int i = 0; i < vals.length; i++) {
stmt.setString(i + 2, vals[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package com.oltpbenchmark.benchmarks.ycsb.procedures;

import com.oltpbenchmark.PrometheusMetrics;
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;
import com.oltpbenchmark.benchmarks.ycsb.YCSBConstants;

import io.prometheus.client.Histogram.Timer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -30,18 +33,20 @@

public class ReadModifyWriteRecord extends Procedure {
public final SQLStmt selectStmt = new SQLStmt(
"SELECT * FROM " + TABLE_NAME + " where YCSB_KEY=? FOR UPDATE"
);
"SELECT * FROM " + TABLE_NAME + " where YCSB_KEY=? FOR UPDATE");
public final SQLStmt updateAllStmt = new SQLStmt(
"UPDATE " + TABLE_NAME + " SET FIELD1=?,FIELD2=?,FIELD3=?,FIELD4=?,FIELD5=?," +
"FIELD6=?,FIELD7=?,FIELD8=?,FIELD9=?,FIELD10=? WHERE YCSB_KEY=?"
);
"FIELD6=?,FIELD7=?,FIELD8=?,FIELD9=?,FIELD10=? WHERE YCSB_KEY=?");

//FIXME: The value in ysqb is a byteiterator
// FIXME: The value in ysqb is a byteiterator
public void run(Connection conn, int keyname, String[] fields, String[] results) throws SQLException {

// Fetch it!
try (PreparedStatement stmt = this.getPreparedStatement(conn, selectStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"read").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, selectStmt)) {
stmt.setInt(1, keyname);
try (ResultSet r = stmt.executeQuery()) {
while (r.next()) {
Expand All @@ -54,7 +59,11 @@ public void run(Connection conn, int keyname, String[] fields, String[] results)
}

// Update that mofo
try (PreparedStatement stmt = this.getPreparedStatement(conn, updateAllStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"write").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, updateAllStmt)) {
stmt.setInt(11, keyname);

for (int i = 0; i < fields.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package com.oltpbenchmark.benchmarks.ycsb.procedures;

import com.oltpbenchmark.PrometheusMetrics;
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;
import com.oltpbenchmark.benchmarks.ycsb.YCSBConstants;

import io.prometheus.client.Histogram.Timer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -30,12 +33,15 @@

public class ReadRecord extends Procedure {
public final SQLStmt readStmt = new SQLStmt(
"SELECT * FROM " + TABLE_NAME + " WHERE YCSB_KEY=?"
);
"SELECT * FROM " + TABLE_NAME + " WHERE YCSB_KEY=?");

//FIXME: The value in ysqb is a byteiterator
// FIXME: The value in ysqb is a byteiterator
public void run(Connection conn, int keyname, String[] results) throws SQLException {
try (PreparedStatement stmt = this.getPreparedStatement(conn, readStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"read").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, readStmt)) {
stmt.setInt(1, keyname);
try (ResultSet r = stmt.executeQuery()) {
while (r.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package com.oltpbenchmark.benchmarks.ycsb.procedures;

import com.oltpbenchmark.PrometheusMetrics;
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;
import com.oltpbenchmark.benchmarks.ycsb.YCSBConstants;

import io.prometheus.client.Histogram.Timer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -31,12 +34,15 @@

public class ScanRecord extends Procedure {
public final SQLStmt scanStmt = new SQLStmt(
"SELECT * FROM " + TABLE_NAME + " WHERE YCSB_KEY>? AND YCSB_KEY<?"
);
"SELECT * FROM " + TABLE_NAME + " WHERE YCSB_KEY>? AND YCSB_KEY<?");

//FIXME: The value in ysqb is a byteiterator
// FIXME: The value in ysqb is a byteiterator
public void run(Connection conn, int start, int count, List<String[]> results) throws SQLException {
try (PreparedStatement stmt = this.getPreparedStatement(conn, scanStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"scan").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, scanStmt)) {
stmt.setInt(1, start);
stmt.setInt(2, start + count);
try (ResultSet r = stmt.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package com.oltpbenchmark.benchmarks.ycsb.procedures;

import com.oltpbenchmark.PrometheusMetrics;
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;

import io.prometheus.client.Histogram.Timer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -30,11 +33,14 @@ public class UpdateRecord extends Procedure {

public final SQLStmt updateAllStmt = new SQLStmt(
"UPDATE " + TABLE_NAME + " SET FIELD1=?,FIELD2=?,FIELD3=?,FIELD4=?,FIELD5=?," +
"FIELD6=?,FIELD7=?,FIELD8=?,FIELD9=?,FIELD10=? WHERE YCSB_KEY=?"
);
"FIELD6=?,FIELD7=?,FIELD8=?,FIELD9=?,FIELD10=? WHERE YCSB_KEY=?");

public void run(Connection conn, int keyname, String[] vals) throws SQLException {
try (PreparedStatement stmt = this.getPreparedStatement(conn, updateAllStmt)) {
try (Timer timer = PrometheusMetrics.STATEMENT_DURATION.labels(
"ycsb",
this.getProcedureName(),
"update").startTimer();
PreparedStatement stmt = this.getPreparedStatement(conn, updateAllStmt)) {

stmt.setInt(11, keyname);
for (int i = 0; i < vals.length; i++) {
Expand All @@ -44,4 +50,3 @@ public void run(Connection conn, int keyname, String[] vals) throws SQLException
}
}
}

0 comments on commit 9b9ae0b

Please sign in to comment.