edu.usc.bg.base
Class Workload

java.lang.Object
  extended by edu.usc.bg.base.Workload
Direct Known Subclasses:
CoreWorkload, FriendshipWorkload, ResourceWorkload, UserWorkload

public abstract class Workload
extends java.lang.Object

One experiment scenario. One object of this type will be instantiated and shared among all client threads. This class should be constructed using a no-argument constructor, so we can load it dynamically. Any argument-based initialization should be done by init().


Constructor Summary
Workload()
           
 
Method Summary
 void cleanup()
          Cleanup the scenario.
abstract  boolean doInsert(DB db, java.lang.Object threadstate)
          Do one insert operation.
abstract  int doTransaction(DB db, java.lang.Object threadstate, int threadid, java.lang.StringBuilder updateLog, java.lang.StringBuilder readLog, int seqID, java.util.HashMap<java.lang.String,java.lang.Integer> resUpdateOperations, java.util.HashMap<java.lang.String,java.lang.Integer> friendshipInfo, java.util.HashMap<java.lang.String,java.lang.Integer> pendingInfo, int thinkTime, boolean insertImage, boolean warmup)
          Do one transaction operation.
abstract  java.util.HashMap<java.lang.String,java.lang.String> getDBInitialStats(DB db)
          Gets the initial statistics from the data stores: member count, friend count per user, pending friend count per user and the resource count per user assuming all users initially have the same number of confirmed and pending friendships.
 void init(java.util.Properties p, java.util.Vector<java.lang.Integer> members)
          Initialize the scenario.
 java.lang.Object initThread(java.util.Properties p, int mythreadid, int threadcount)
          Initialize any state for a particular client thread.
 boolean isStopRequested()
          Check the status of the stop request flag.
 void requestStop()
          Allows scheduling a request to stop the workload.
 boolean resetDBInternalStructures(java.util.Properties p, int executionMode)
          Initialize the internal data structures keeping a track of databases state.
 void setStopRequested(boolean value)
          Check the status of the stop request flag.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Workload

public Workload()
Method Detail

init

public void init(java.util.Properties p,
                 java.util.Vector<java.lang.Integer> members)
          throws WorkloadException
Initialize the scenario. Create any generators and other shared objects here. Called once, in the main client thread, before any operations are started. Also called when client threads load the database.

Parameters:
p - The properties.
members - Needed for the load phase, keeps a track of the set of memberids that the BG client is responsible for.
Throws:
WorkloadException

resetDBInternalStructures

public boolean resetDBInternalStructures(java.util.Properties p,
                                         int executionMode)
Initialize the internal data structures keeping a track of databases state. Create any generators and other shared objects here. Called with the continual mode of executing BG.

Parameters:
p - The properties.
executionMode - (0 stands for single and 1 stands for continual mode of operation)
Returns:
true if everything with settinguo the structures is fine or if the structures are already available

initThread

public java.lang.Object initThread(java.util.Properties p,
                                   int mythreadid,
                                   int threadcount)
                            throws WorkloadException
Initialize any state for a particular client thread. Since the scenario object will be shared among all threads, this is the place to create any state that is specific to one thread. To be clear, this means the returned object should be created anew on each call to initThread(); do not return the same object multiple times. The returned object will be passed to invocations of doInsert() and doTransaction() for this thread. There should be no side effects from this call; all state should be encapsulated in the returned object. If you have no state to retain for this thread, return null. (But if you have no state to retain for this thread, probably you don't need to override initThread().)

Returns:
false if the workload knows it is done for this thread. Client will terminate the thread. Return true otherwise. Return true for workloads that rely on operationcount. For workloads that read traces from a file, return true when there are more to do, false when you are done.
Throws:
WorkloadException

cleanup

public void cleanup()
             throws WorkloadException
Cleanup the scenario. Called once, in the main client thread, after all operations have completed.

Throws:
WorkloadException

doInsert

public abstract boolean doInsert(DB db,
                                 java.lang.Object threadstate)
Do one insert operation. Because it will be called concurrently from multiple client threads, this function must be thread safe. However, avoid synchronized, or the threads will block waiting for each other, and it will be difficult to reach the target throughput. Ideally, this function would have no side effects other than DB operations and mutations on threadstate. Mutations to threadstate do not need to be synchronized, since each thread has its own threadstate instance.


doTransaction

public abstract int doTransaction(DB db,
                                  java.lang.Object threadstate,
                                  int threadid,
                                  java.lang.StringBuilder updateLog,
                                  java.lang.StringBuilder readLog,
                                  int seqID,
                                  java.util.HashMap<java.lang.String,java.lang.Integer> resUpdateOperations,
                                  java.util.HashMap<java.lang.String,java.lang.Integer> friendshipInfo,
                                  java.util.HashMap<java.lang.String,java.lang.Integer> pendingInfo,
                                  int thinkTime,
                                  boolean insertImage,
                                  boolean warmup)
Do one transaction operation. Because it will be called concurrently from multiple client threads, this function must be thread safe. However, avoid synchronized, or the threads will block waiting for each other, and it will be difficult to reach the target throughput. Ideally, this function would have no side effects other than DB operations and mutations on threadstate. Mutations to threadstate do not need to be synchronized, since each thread has its own threadstate instance.

Parameters:
updateLog - The update log record created by that transaction which needs to be written to the update file.
readLog - The read log record created by that transaction which needs to be written to the update file.
seqID - For workloads issuing sessions keeps a track of the current sessionid.
resUpdateOperations - Keeps a track of all the postcomment updates issued - needed for validation based on exact values.
friendshipInfo - Keeps a track of all the confirmed friendships created throughout the benchmark execution - needed for validation based on exact values.
pendingInfo - Keeps a track of all the pending invites created during the benchmark execution - needed for validation based on exact values.
thinkTime - Think time between the actions in a session.
insertImage - If set to true means images will be retrieved for relevant actions i.e. getUserProfile.
warmup - If set to true the workload would not issue any update actions.
Returns:
greater than 0 if everything is fine.

getDBInitialStats

public abstract java.util.HashMap<java.lang.String,java.lang.String> getDBInitialStats(DB db)
Gets the initial statistics from the data stores: member count, friend count per user, pending friend count per user and the resource count per user assuming all users initially have the same number of confirmed and pending friendships.


requestStop

public void requestStop()
Allows scheduling a request to stop the workload.


isStopRequested

public boolean isStopRequested()
Check the status of the stop request flag.

Returns:
true if stop was requested, false otherwise.

setStopRequested

public void setStopRequested(boolean value)
Check the status of the stop request flag. return true if stop was requested, false otherwise.