use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class BidGenerator method run.
/**
* This is the "run" method for this Runnable subclass.
*
* Generate one new row for the bids table, and insert it.
*/
@Override
public void run() {
long bidId = m_bidId++;
long advertiserId = Math.abs(m_rand.nextLong()) % NUM_ADVERTISERS;
GeographyValue bidRegion = Regions.pickRandomRegion();
TimestampType bidStartTime = new TimestampType();
TimestampType bidEndTime = new TimestampType(bidStartTime.getTime() + AdBrokerBenchmark.BID_DURATION_SECONDS * 1000000);
// Amount of bid: a hundredth of a penny up to around a tenth of a penny.
double amount = 0.00001 + 0.01 * m_rand.nextDouble();
DecimalFormat df = new DecimalFormat("#.####");
amount = Double.valueOf(df.format(amount));
try {
m_client.callProcedure(new NullCallback(), "bids.Insert", bidId, advertiserId, bidRegion, bidStartTime, bidEndTime, amount);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class AdTrackingBenchmark method iterate.
public void iterate() throws Exception {
// generate an impression
// each iteration is 1 millisecond later
// the faster the throughput rate, the faster time flies!
// this is to get more interesting hourly or minutely results
iteration++;
TimestampType ts = new TimestampType(startTime + (iteration * 1000));
// random IP address
int ipAddress = rand.nextInt(256) * 256 * 256 * 256 + rand.nextInt(256) * 256 * 256 + rand.nextInt(256) * 256 + rand.nextInt(256);
long cookieUID = rand.nextInt(1000000000);
int creative = rand.nextInt(creativeMaxID) + 1;
int inventory = rand.nextInt(inventoryMaxID) + 1;
BigDecimal cost = new BigDecimal(rand.nextDouble() / 5, mc);
client.callProcedure(new BenchmarkCallback("TrackEvent"), "TrackEvent", ts, ipAddress, cookieUID, creative, inventory, 0, cost);
int i = rand.nextInt(100);
int r = creative % modulus;
// sometimes generate a click-through
if ((r == 0 && i < 10) || i == 0) {
// 1% of the time at least, for 1/3 of campaigns 10% of the time
client.callProcedure(new BenchmarkCallback("TrackEvent"), "TrackEvent", ts, ipAddress, cookieUID, creative, inventory, 1, bd0);
// 33% conversion rate
if (rand.nextInt(2) == 0) {
client.callProcedure(new BenchmarkCallback("TrackEvent"), "TrackEvent", ts, ipAddress, cookieUID, creative, inventory, 2, bd0);
}
}
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class BeginCall method run.
/**
* Procedure main logic.
*
* @param uuid Column value for tuple insertion and partitioning key for this procedure.
* @param val Column value for tuple insertion.
* @param update_ts Column value for tuple insertion.
* @param newestToDiscard Try to remove any tuples as old or older than this value.
* @param targetMaxRowsToDelete The upper limit on the number of rows to delete per transaction.
* @return The number of deleted rows.
* @throws VoltAbortException on bad input.
*/
public long run(int agent_id, String phone_no, long call_id, TimestampType start_ts) {
voltQueueSQL(findOpenCall, EXPECT_ZERO_OR_ONE_ROW, call_id, agent_id, phone_no);
voltQueueSQL(findCompletedCall, EXPECT_ZERO_OR_ONE_ROW, call_id, agent_id, phone_no);
VoltTable[] results = voltExecuteSQL();
boolean completedCall = results[1].getRowCount() > 0;
if (completedCall) {
return -1;
}
VoltTable openRowTable = results[0];
if (openRowTable.getRowCount() > 0) {
VoltTableRow existingCall = openRowTable.fetchRow(0);
// check if this is the second begin we've seen for this open call
existingCall.getTimestampAsTimestamp("start_ts");
if (existingCall.wasNull() == false) {
return -1;
}
// check if this completes the call
TimestampType end_ts = existingCall.getTimestampAsTimestamp("end_ts");
if (existingCall.wasNull() == false) {
int durationms = (int) ((end_ts.getTime() - start_ts.getTime()) / 1000);
// update per-day running stddev calculation
computeRunningStdDev(agent_id, end_ts, durationms);
// completes the call
voltQueueSQL(deleteOpenCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no);
voltQueueSQL(insertCompletedCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no, start_ts, end_ts, durationms);
voltExecuteSQL(true);
return 0;
}
}
voltQueueSQL(upsertOpenCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no, start_ts);
voltExecuteSQL(true);
return 0;
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class OfferBenchmark method iterate.
public void iterate() throws Exception {
// pick a random account and generate a transaction
int i = rand.nextInt(accounts.length);
txnId++;
long acctNo = accounts[i];
double txnAmt = amounts[rand.nextInt(amounts.length)];
String txnState = acct_states[i];
String txnCity = "Some City";
TimestampType txnTS = new TimestampType();
int vendorId = rand.nextInt(config.vendorcount);
// a small % of the time, use a random state
if (rand.nextInt(50000) == 0) {
txnState = PersonGenerator.randomState();
}
client.callProcedure(new BenchmarkCallback("CheckForOffers"), "CheckForOffers", txnId, acctNo, txnAmt, txnState, txnCity, txnTS, vendorId);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class AuctionStatus method run.
/**
* Get a tuple of useful status info about an auction.
*
* @param itemId The id of the item we'd like to know about.
* @return A table with one row and fields:
* (item, bidder, seller, bidcount, price, endtime, status)
* @throws VoltAbortException Currently doesn't abort.
*/
public VoltTable[] run(int itemId) throws VoltAbortException {
// create a new VoltTable to store our results
VoltTable retval = new VoltTable(new VoltTable.ColumnInfo("item", VoltType.STRING), new VoltTable.ColumnInfo("bidder", VoltType.STRING), new VoltTable.ColumnInfo("seller", VoltType.STRING), new VoltTable.ColumnInfo("bidcount", VoltType.BIGINT), new VoltTable.ColumnInfo("price", VoltType.FLOAT), new VoltTable.ColumnInfo("endtime", VoltType.TIMESTAMP), new VoltTable.ColumnInfo("status", VoltType.STRING));
// get the seller id and item name from ITEM table
voltQueueSQL(getItemInfo, itemId);
VoltTable itemTable = voltExecuteSQL()[0];
VoltTableRow itemRow = itemTable.fetchRow(0);
// resulting info:
long sellerId = itemRow.getLong("SELLERID");
String itemName = itemRow.getString("ITEMNAME");
long endTime = itemRow.getTimestampAsLong("ENDTIME");
long highBidId = itemRow.getLong("HIGHBIDID");
// get high bid info
voltQueueSQL(getBidInfo, highBidId);
VoltTable statusTable = voltExecuteSQL()[0];
VoltTableRow row = statusTable.fetchRow(0);
// resulting info:
long bidderId = row.getLong("BIDDERID");
double bidPrice = row.getDouble("BIDPRICE");
// count the number of bids on the auction
voltQueueSQL(getBidCount, itemId);
VoltTable bidCountTable = voltExecuteSQL()[0];
VoltTableRow bidCountRow = bidCountTable.fetchRow(0);
// resulting info:
// the minus one is for the fake initial bid
long bidCount = bidCountRow.getLong(0) - 1;
// get the names of the bidder and seller
voltQueueSQL(getUserName, sellerId);
if (bidderId >= 0) {
voltQueueSQL(getUserName, bidderId);
}
VoltTable[] nameTables = voltExecuteSQL();
VoltTableRow sellerNameRow = nameTables[0].fetchRow(0);
// we should always have a seller name
String sellerName = sellerNameRow.getString("FIRSTNAME") + " " + sellerNameRow.getString("LASTNAME");
// we might not always have a bidder name, so need this if statement
String bidderName = "NO BIDDER";
if (bidderId >= 0) {
VoltTableRow bidderNameRow = nameTables[1].fetchRow(0);
bidderName = bidderNameRow.getString("FIRSTNAME") + " " + bidderNameRow.getString("LASTNAME");
}
// check the timing and set the auction status accordingly
String status = "OPEN";
long now = new TimestampType().getTime();
if (endTime < now)
status = "CLOSED";
// add the single tuple to our return table
retval.addRow(itemName, bidderName, sellerName, bidCount, bidPrice, endTime, status);
return new VoltTable[] { retval };
}
Aggregations