com.yahoo.ycsb
Class Workload

java.lang.Object
  extended by com.yahoo.ycsb.Workload
Direct Known Subclasses:
CoreWorkload

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(). If you extend this class, you should support the "insertstart" property. This allows the load phase to proceed from multiple clients on different machines, in case the client is the bottleneck. For example, if we want to load 1 million records from 2 machines, the first machine should have insertstart=0 and the second insertstart=500000. Additionally, the "insertcount" property, which is interpreted by Client, can be used to tell each instance of the client how many inserts to do. In the example above, both clients should have insertcount=500000.


Field Summary
static java.lang.String INSERT_START_PROPERTY
           
static java.lang.String INSERT_START_PROPERTY_DEFAULT
           
 
Constructor Summary
Workload()
           
 
Method Summary
 void cleanup()
          Cleanup the scenario.
abstract  boolean doInsert(DB db, java.lang.Object threadstate)
          Do one insert operation.
abstract  boolean doTransaction(DB db, java.lang.Object threadstate)
          Do one transaction operation.
 void init(java.util.Properties p)
          Initialize the scenario.
 java.lang.Object initThread(java.util.Properties p, int mythreadid, int threadcount)
          Initialize any state for a particular client thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSERT_START_PROPERTY

public static final java.lang.String INSERT_START_PROPERTY
See Also:
Constant Field Values

INSERT_START_PROPERTY_DEFAULT

public static final java.lang.String INSERT_START_PROPERTY_DEFAULT
See Also:
Constant Field Values
Constructor Detail

Workload

public Workload()
Method Detail

init

public void init(java.util.Properties p)
          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.

Throws:
WorkloadException

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 boolean doTransaction(DB db,
                                      java.lang.Object threadstate)
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.

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.