Package org.apache.bookkeeper.proto

Examples of org.apache.bookkeeper.proto.BookieClient$Completion


    OrderedSafeExecutor executor = new OrderedSafeExecutor(1);


    public BookieBenchmark(String bookieHostPortthrows Exception {
        channelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
        bkc = new BookieClient(new ClientConfiguration(), channelFactory, executor);
        String[] hostPort = bookieHostPort.split(":");
        addr = new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1]));

    }
View Full Code Here


            = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors
                                                .newCachedThreadPool());
        OrderedSafeExecutor executor = new OrderedSafeExecutor(1);

        ClientConfiguration conf = new ClientConfiguration();
        BookieClient bc = new BookieClient(conf, channelFactory, executor);
        LatencyCallback lc = new LatencyCallback();

        ThroughputCallback tc = new ThroughputCallback();
        int warmUpCount = 999;

        long ledger = getValidLedgerId(servers);
        for(long entry = 0; entry < warmUpCount; entry++) {
            ChannelBuffer toSend = ChannelBuffers.buffer(size);
            toSend.resetReaderIndex();
            toSend.resetWriterIndex();
            toSend.writeLong(ledger);
            toSend.writeLong(entry);
            toSend.writerIndex(toSend.capacity());
            bc.addEntry(new InetSocketAddress(addr, port), ledger, new byte[20],
                        entry, toSend, tc, null, BookieProtocol.FLAG_NONE);
        }
        LOG.info("Waiting for warmup");
        tc.waitFor(warmUpCount);

        ledger = getValidLedgerId(servers);
        LOG.info("Benchmarking latency");
        int entryCount = 5000;
        long startTime = System.nanoTime();
        for(long entry = 0; entry < entryCount; entry++) {
            ChannelBuffer toSend = ChannelBuffers.buffer(size);
            toSend.resetReaderIndex();
            toSend.resetWriterIndex();
            toSend.writeLong(ledger);
            toSend.writeLong(entry);
            toSend.writerIndex(toSend.capacity());
            lc.resetComplete();
            bc.addEntry(new InetSocketAddress(addr, port), ledger, new byte[20],
                        entry, toSend, lc, null, BookieProtocol.FLAG_NONE);
            lc.waitForComplete();
        }
        long endTime = System.nanoTime();
        LOG.info("Latency: " + (((double)(endTime-startTime))/((double)entryCount))/1000000.0);

        entryCount = 50000;

        ledger = getValidLedgerId(servers);
        LOG.info("Benchmarking throughput");
        startTime = System.currentTimeMillis();
        tc = new ThroughputCallback();
        for(long entry = 0; entry < entryCount; entry++) {
            ChannelBuffer toSend = ChannelBuffers.buffer(size);
            toSend.resetReaderIndex();
            toSend.resetWriterIndex();
            toSend.writeLong(ledger);
            toSend.writeLong(entry);
            toSend.writerIndex(toSend.capacity());
            bc.addEntry(new InetSocketAddress(addr, port), ledger, new byte[20],
                        entry, toSend, tc, null, BookieProtocol.FLAG_NONE);
        }
        tc.waitFor(entryCount);
        endTime = System.currentTimeMillis();
        LOG.info("Throughput: " + ((long)entryCount)*1000/(endTime-startTime));

        bc.close();
        channelFactory.releaseExternalResources();
        executor.shutdown();
    }
View Full Code Here

         * Create BookieClient objects and send a request to each one.
         */
       
        for(InetSocketAddress s : bookies){
            LOG.info(s);
            BookieClient client = new BookieClient(s, 3000);
            clients.add(client);
            client.readEntry(lId,
                    -1,
                    this,
                    null);
        }       
       
View Full Code Here

    public void testWriteGaps() throws Exception {
        final Object notifyObject = new Object();
        byte[] passwd = new byte[20];
        Arrays.fill(passwd, (byte) 'a');
       
        BookieClient bc = new BookieClient("127.0.0.1", port, 50000);
        ByteBuffer bb;
        bb = createByteBuffer(1,1,1);
        bc.addEntry(1, passwd, 1, bb, wrcb, null);
        bb = createByteBuffer(2,1,2);
        bc.addEntry(1, passwd, 2, bb, wrcb, null);
        bb = createByteBuffer(3,1,3);
        bc.addEntry(1, passwd, 3, bb, wrcb, null);
        bb = createByteBuffer(5,1,5);
        bc.addEntry(1, passwd, 5, bb, wrcb, null);
        bb = createByteBuffer(7,1,7);
        bc.addEntry(1, passwd, 7, bb, wrcb, null);
        synchronized(notifyObject) {
            bb = createByteBuffer(11,1,11);
            bc.addEntry(1, passwd, 11, bb, wrcb, notifyObject);
            notifyObject.wait();
        }
        ResultStruct arc = new ResultStruct();
        synchronized(arc) {
            bc.readEntry(1, 6, recb, arc);
            arc.wait(1000);
            assertEquals(BookieProtocol.ENOENTRY, arc.rc);
        }
        synchronized(arc) {
            bc.readEntry(1, 7, recb, arc);
            arc.wait(1000);
            assertEquals(0, arc.rc);
            assertEquals(7, arc.entry.getInt());
        }
        synchronized(arc) {
            bc.readEntry(1, 1, recb, arc);
            arc.wait(1000);
            assertEquals(0, arc.rc);
            assertEquals(1, arc.entry.getInt());
        }
        synchronized(arc) {
            bc.readEntry(1, 2, recb, arc);
            arc.wait(1000);
            assertEquals(0, arc.rc);
            assertEquals(2, arc.entry.getInt());
        }
        synchronized(arc) {
            bc.readEntry(1, 3, recb, arc);
            arc.wait(1000);
            assertEquals(0, arc.rc);
            assertEquals(3, arc.entry.getInt());
        }
        synchronized(arc) {
            bc.readEntry(1, 4, recb, arc);
            arc.wait(1000);
            assertEquals(BookieProtocol.ENOENTRY, arc.rc);
        }
        synchronized(arc) {
            bc.readEntry(1, 11, recb, arc);
            arc.wait(1000);
            assertEquals(0, arc.rc);
            assertEquals(11, arc.entry.getInt());
        }
        synchronized(arc) {
            bc.readEntry(1, 5, recb, arc);
            arc.wait(1000);
            assertEquals(0, arc.rc);
            assertEquals(5, arc.entry.getInt());
        }
        synchronized(arc) {
            bc.readEntry(1, 10, recb, arc);
            arc.wait(1000);
            assertEquals(BookieProtocol.ENOENTRY, arc.rc);
        }
        synchronized(arc) {
            bc.readEntry(1, 12, recb, arc);
            arc.wait(1000);
            assertEquals(BookieProtocol.ENOENTRY, arc.rc);
        }
        synchronized(arc) {
            bc.readEntry(1, 13, recb, arc);
            arc.wait(1000);
            assertEquals(BookieProtocol.ENOENTRY, arc.rc);
        }
    }
View Full Code Here

        return bb;
    }
    @Test
    public void testNoLedger() throws Exception {
        ResultStruct arc = new ResultStruct();
        BookieClient bc = new BookieClient("127.0.0.1", port, 50000);
        synchronized(arc) {
            bc.readEntry(2, 13, recb, arc);
            arc.wait(1000);
            assertEquals(BookieProtocol.ENOLEDGER, arc.rc);
        }
    }
View Full Code Here

    }
   
    LoopbackClient(int port, long begin, int limit)
    throws IOException {
        this.client =
            new BookieClient(new InetSocketAddress("127.0.0.1", port), recvTimeout);
        this.begin = begin;
    }
View Full Code Here

     */
    BookieHandle(InetSocketAddress addr, boolean enabled) throws IOException {
        this.stop = !enabled;
        this.noreception = !enabled;
        if(!stop)
            this.client = new BookieClient(addr, recvTimeout);
        else
            this.client = null;
       
        this.addr = addr;
        this.incomingQueue = new ArrayBlockingQueue<ToSend>(2000);
View Full Code Here

     *
     * @return
     * @throws IOException
     */
    void restart() throws IOException {
        this.client = new BookieClient(addr, recvTimeout);
    }
View Full Code Here

TOP

Related Classes of org.apache.bookkeeper.proto.BookieClient$Completion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.