Search in sources :

Example 11 with SimpleStopwatch

use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.

the class ClientTool method doAction.

public void doAction(ClientOptions options) throws Exception {
    DHTSession session;
    Action action;
    SynchronousNamespacePerspective<String, byte[]> syncNSP;
    Stopwatch sw;
    int outerReps;
    NamespacePerspectiveOptions<String, byte[]> nspOptions;
    // FUTURE - IMPLEMENT VALIDATION FLAG
    // DHTClient.setValidateChecksums(!options.noValidation);
    // note - server may be null
    session = dhtClient.openSession(new SessionOptions(SKGridConfiguration.parseFile(options.gridConfig), options.server));
    if (session == null) {
        throw new RuntimeException("null session");
    }
    if (options.action != Action.CreateNamespace) {
        Namespace ns;
        ns = session.getNamespace(options.namespace);
        nspOptions = ns.getDefaultNSPOptions(String.class, byte[].class);
        if (options.checksumType != null) {
            nspOptions = nspOptions.defaultPutOptions(session.getDefaultPutOptions().checksumType(options.checksumType));
        }
        syncNSP = ns.openSyncPerspective(nspOptions);
    } else {
        syncNSP = null;
    }
    // syncNSP = session.openSyncNamespacePerspective(options.namespace, nspOptions);
    if (options.warmup) {
        outerReps = 2;
    } else {
        outerReps = 1;
    }
    for (int i = 0; i < outerReps; i++) {
        sw = new SimpleStopwatch();
        try {
            action = options.action;
            switch(action) {
                case Put:
                    doPut(options, session, syncNSP, sw);
                    break;
                case MultiPut:
                    doMultiPut(options, session, syncNSP, sw);
                    break;
                case MultiGet:
                    doMultiGet(options, syncNSP, sw);
                    break;
                case Get:
                    doGet(options, syncNSP, sw);
                    break;
                case GetMeta:
                    doGetMeta(options, syncNSP, sw);
                    break;
                case GetValueAndMeta:
                    doGetValueAndMeta(options, syncNSP, sw);
                    break;
                case WaitFor:
                    doWaitFor(options, syncNSP, sw);
                    break;
                case Snapshot:
                    doSnapshot(options, syncNSP, sw);
                    break;
                case SyncRequest:
                    doSyncRequest(options, syncNSP, sw);
                    break;
                case CreateNamespace:
                    doCreateNamespace(options, session, sw);
                    break;
                case GetNamespaceOptions:
                    doGetNamespaceOptions(options, session, sw);
                    break;
                default:
                    throw new RuntimeException("panic");
            }
        } finally {
            session.close();
        }
        // sw.stop();
        Log.warning("Elapsed:\t" + sw.getElapsedSeconds());
        if (options.warmup || i < outerReps - 1) {
            ThreadUtil.sleep(warmupDelayMillis);
        }
    }
}
Also used : SessionOptions(com.ms.silverking.cloud.dht.SessionOptions) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) Namespace(com.ms.silverking.cloud.dht.client.Namespace)

Example 12 with SimpleStopwatch

use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.

the class ProducerConsumer method run.

public void run(int items) throws PutException, RetrievalException {
    Stopwatch sw;
    sw = new SimpleStopwatch();
    for (int i = 1; i <= items; i++) {
        switch(mode) {
            case Producer:
                produce(i);
                break;
            case Consumer:
                consume(i);
                break;
            default:
                throw new RuntimeException("panic");
        }
        ThreadUtil.sleep(delay);
    }
    sw.stop();
    System.out.println(sw);
}
Also used : Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 13 with SimpleStopwatch

use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.

the class ChannelWriteTest method runTest.

public void runTest(Test test, int valueSize, int numValues, int iterations) throws IOException {
    Stopwatch sw;
    byte[] value;
    byte[] checksum;
    int entrySize;
    int totalBytes;
    GatheringByteChannel outChannel;
    long totalWritten;
    ByteBuffer valuesBuffer;
    ByteBuffer[] buffers;
    entrySize = valueSize + checksumSize;
    totalBytes = entrySize * numValues;
    value = new byte[valueSize];
    checksum = new byte[checksumSize];
    random.nextBytes(value);
    outChannel = new FileOutputStream(new File("/dev/null")).getChannel();
    sw = new SimpleStopwatch();
    switch(test) {
        case array:
            {
                byte[] msg;
                for (int j = 0; j < iterations; j++) {
                    msg = new byte[totalBytes];
                    for (int i = 0; i < numValues; i++) {
                        System.arraycopy(value, 0, msg, i * entrySize, valueSize);
                        System.arraycopy(checksum, 0, msg, i * entrySize + valueSize, checksumSize);
                    }
                    valuesBuffer = ByteBuffer.wrap(msg);
                    totalWritten = 0;
                    while (totalWritten < totalBytes) {
                        long written;
                        written = outChannel.write(valuesBuffer);
                        if (written > 0) {
                            totalWritten += written;
                        }
                    }
                    if (totalWritten != totalBytes) {
                        throw new RuntimeException("totalWritten != totalBytes");
                    }
                }
            }
            break;
        case buffer:
            buffers = new ByteBuffer[numValues * 2];
            for (int i = 0; i < numValues; i++) {
                buffers[i * 2] = ByteBuffer.allocate(value.length);
                buffers[i * 2 + 1] = ByteBuffer.allocate(checksum.length);
            }
            sw.reset();
            sendBuffers(buffers, iterations, totalBytes, outChannel);
            break;
        case direct:
            buffers = new ByteBuffer[numValues * 2];
            for (int i = 0; i < numValues; i++) {
                buffers[i * 2] = ByteBuffer.allocateDirect(valueSize);
                // buffers[i * 2].put(value);
                // buffers[i * 2].flip();
                buffers[i * 2 + 1] = ByteBuffer.allocateDirect(checksumSize);
            // buffers[i * 2 + 1].put(checksum);
            // buffers[i * 2 + 1].flip();
            }
            sw.reset();
            sendBuffers(buffers, iterations, totalBytes, outChannel);
            break;
        case mixed:
            buffers = new ByteBuffer[numValues * 2];
            for (int i = 0; i < numValues; i++) {
                buffers[i * 2] = ByteBuffer.allocateDirect(valueSize);
                // buffers[i * 2].put(value);
                // buffers[i * 2].flip();
                buffers[i * 2 + 1] = ByteBuffer.allocate(checksum.length);
            // buffers[i * 2 + 1].put(checksum);
            // buffers[i * 2 + 1].flip();
            }
            sw.reset();
            sendBuffers(buffers, iterations, totalBytes, outChannel);
            break;
    }
    sw.stop();
    System.out.printf("%s\tTime per iteration %e\n", test.toString(), sw.getElapsedSeconds() / (double) iterations);
}
Also used : GatheringByteChannel(java.nio.channels.GatheringByteChannel) FileOutputStream(java.io.FileOutputStream) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) ByteBuffer(java.nio.ByteBuffer) File(java.io.File)

Example 14 with SimpleStopwatch

use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.

the class RingTree method getResolvedMap.

// ///////////////////////////////
public ResolvedReplicaMap getResolvedMap(String ringParentName, ReplicaPrioritizer replicaPrioritizer) {
    try {
        ResolvedReplicaMap resolvedMap;
        List<RingEntry> entryList;
        Node node;
        Stopwatch sw;
        Log.warningf("getResolvedMap: %s", ringParentName);
        sw = new SimpleStopwatch();
        resolvedMap = new ResolvedReplicaMap(replicaPrioritizer);
        if (debug) {
            System.out.println("getResolvedMap: " + topology.getRoot());
        }
        node = topology.getNodeByID(ringParentName);
        if (node == null) {
            throw new RuntimeException("Unable to getNodeByID " + ringParentName);
        }
        entryList = project(node, LongRingspace.globalRegion);
        for (RingEntry entry : entryList) {
            resolvedMap.addEntry(entry);
        }
        resolvedMap.computeReplicaSet();
        sw.stop();
        Log.warningf("getResolvedMap: %s complete %f", ringParentName, sw.getElapsedSeconds());
        return resolvedMap;
    } catch (RuntimeException re) {
        re.printStackTrace();
        throw re;
    }
}
Also used : DHTNode(com.ms.silverking.cloud.dht.daemon.DHTNode) Node(com.ms.silverking.cloud.topology.Node) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Example 15 with SimpleStopwatch

use of com.ms.silverking.time.SimpleStopwatch in project SilverKing by Morgan-Stanley.

the class StorageModule method reap.

public void reap(boolean leaveTrash) {
    Stopwatch sw;
    Log.warning("Reap");
    sw = new SimpleStopwatch();
    for (NamespaceStore ns : namespaces.values()) {
        if (!ns.isDynamic()) {
            ns.reap(leaveTrash);
        }
    }
    sw.stop();
    Log.warning("Reap complete: " + sw);
}
Also used : Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch)

Aggregations

SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)42 Stopwatch (com.ms.silverking.time.Stopwatch)41 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)7 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 SimpleTimer (com.ms.silverking.time.SimpleTimer)3 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)2 DHTKeyIntEntry (com.ms.silverking.cloud.dht.collection.DHTKeyIntEntry)2 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)2 StatSeries (com.ms.silverking.numeric.StatSeries)2 Timer (com.ms.silverking.time.Timer)2 FileOutputStream (java.io.FileOutputStream)2 Date (java.util.Date)2 Map (java.util.Map)2 Random (java.util.Random)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 GetOptions (com.ms.silverking.cloud.dht.GetOptions)1 NamespaceOptions (com.ms.silverking.cloud.dht.NamespaceOptions)1 NamespaceVersionMode (com.ms.silverking.cloud.dht.NamespaceVersionMode)1 PutOptions (com.ms.silverking.cloud.dht.PutOptions)1