Search in sources :

Example 1 with ServerViewController

use of bftsmart.reconfiguration.ServerViewController in project aware by bergerch.

the class Test method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception {
    // ******* EDUARDO BEGIN **************//
    ServerViewController controller = new ServerViewController(Integer.parseInt(args[0]), null, null);
    LinkedBlockingQueue<SystemMessage> inQueue = new LinkedBlockingQueue<SystemMessage>();
    ServersCommunicationLayer scl = new ServersCommunicationLayer(controller, inQueue, null);
    int id = controller.getStaticConf().getProcessId();
    int n = controller.getCurrentViewN();
    // ******* EDUARDO END **************//
    int[] targets = new int[n - 1];
    System.out.println("n = " + n);
    for (int i = 1; i < n; i++) {
        targets[i - 1] = i;
    }
    int iteractions = Integer.parseInt(args[1]);
    int warmup = iteractions / 2;
    int test = iteractions / 2;
    for (int i = 0; i < warmup; i++) {
        String msg = "m" + i;
        if (id == 0) {
            long time = System.nanoTime();
            scl.send(targets, new TOMMessage(id, 0, 0, i, msg.getBytes(), 0, TOMMessageType.ORDERED_REQUEST), true);
            int rec = 0;
            while (rec < n - 1) {
                inQueue.take();
                rec++;
            }
            // System.out.println();
            System.out.println("Roundtrip " + ((System.nanoTime() - time) / 1000.0) + " us");
        } else {
            TOMMessage m = (TOMMessage) inQueue.take();
            scl.send(new int[] { m.getSender() }, new TOMMessage(id, 0, 0, i, m.getContent(), 0, TOMMessageType.ORDERED_REQUEST), true);
        }
    }
    System.out.println("Beginning the real test with " + test + " roundtrips");
    Storage st = new Storage(test);
    for (int i = 0; i < test; i++) {
        String msg = "m" + i;
        if (id == 0) {
            long time = System.nanoTime();
            scl.send(targets, new TOMMessage(id, 0, 0, i, msg.getBytes(), 0, TOMMessageType.ORDERED_REQUEST), true);
            int rec = 0;
            while (rec < n - 1) {
                inQueue.take();
                rec++;
            }
            st.store(System.nanoTime() - time);
        } else {
            TOMMessage m = (TOMMessage) inQueue.take();
            scl.send(new int[] { m.getSender() }, new TOMMessage(id, 0, 0, i, m.getContent(), 0, TOMMessageType.ORDERED_REQUEST), true);
        }
    }
    System.out.println("Average time for " + test + " executions (-10%) = " + st.getAverage(true) / 1000 + " us ");
    System.out.println("Standard desviation for " + test + " executions (-10%) = " + st.getDP(true) / 1000 + " us ");
    System.out.println("Maximum time for " + test + " executions (-10%) = " + st.getMax(true) / 1000 + " us ");
    System.out.println("Average time for " + test + " executions (all samples) = " + st.getAverage(false) / 1000 + " us ");
    System.out.println("Standard desviation for " + test + " executions (all samples) = " + st.getDP(false) / 1000 + " us ");
    System.out.println("Maximum time for " + test + " executions (all samples) = " + st.getMax(false) / 1000 + " us ");
// scl.shutdown();
}
Also used : TOMMessage(bftsmart.tom.core.messages.TOMMessage) SystemMessage(bftsmart.communication.SystemMessage) Storage(bftsmart.tom.util.Storage) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ServerViewController(bftsmart.reconfiguration.ServerViewController)

Example 2 with ServerViewController

use of bftsmart.reconfiguration.ServerViewController in project bftsmart by blockchain-jd-com.

the class TestNodeServer method startNode.

public ServiceReplica startNode(String realmName) {
    TOMConfiguration config = initConfig();
    try {
        // mock messsageHandler and cs
        MessageHandler messageHandler = new MessageHandler();
        MessageHandler mockMessageHandler = Mockito.spy(messageHandler);
        ClientCommunicationServerSide clientCommunication = ClientCommunicationFactory.createServerSide(new ServerViewController(config, new MemoryBasedViewStorage(latestView)));
        ServerCommunicationSystem cs = new ServerCommunicationSystemImpl(clientCommunication, mockMessageHandler, new ServerViewController(config, new MemoryBasedViewStorage(latestView)), realmName);
        ServerCommunicationSystem mockCs = Mockito.spy(cs);
        replica = new ServiceReplica(mockMessageHandler, mockCs, config, this, this, (int) -1, latestView, realmName);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return replica;
}
Also used : ClientCommunicationServerSide(bftsmart.communication.client.ClientCommunicationServerSide) ServiceReplica(bftsmart.tom.ServiceReplica) ServerCommunicationSystemImpl(bftsmart.communication.ServerCommunicationSystemImpl) MessageHandler(bftsmart.communication.MessageHandler) ServerCommunicationSystem(bftsmart.communication.ServerCommunicationSystem) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration) ServerViewController(bftsmart.reconfiguration.ServerViewController) IOException(java.io.IOException)

Aggregations

ServerViewController (bftsmart.reconfiguration.ServerViewController)2 MessageHandler (bftsmart.communication.MessageHandler)1 ServerCommunicationSystem (bftsmart.communication.ServerCommunicationSystem)1 ServerCommunicationSystemImpl (bftsmart.communication.ServerCommunicationSystemImpl)1 SystemMessage (bftsmart.communication.SystemMessage)1 ClientCommunicationServerSide (bftsmart.communication.client.ClientCommunicationServerSide)1 TOMConfiguration (bftsmart.reconfiguration.util.TOMConfiguration)1 MemoryBasedViewStorage (bftsmart.reconfiguration.views.MemoryBasedViewStorage)1 ServiceReplica (bftsmart.tom.ServiceReplica)1 TOMMessage (bftsmart.tom.core.messages.TOMMessage)1 Storage (bftsmart.tom.util.Storage)1 IOException (java.io.IOException)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1