Package com.yammer.metrics.core

Examples of com.yammer.metrics.core.TimerContext


        }
    }

    @PUT
    public void put(final String text) {
        final TimerContext timer = putTimer.time();
        timer.stop();
    }
View Full Code Here


        timer.stop();
    }

    @GET
    public String get() {
        final TimerContext timer = getTimer.time();
        try {
            return "text";
        } finally {
            timer.stop();
        }
    }
View Full Code Here

    private static final com.yammer.metrics.core.Timer putTimer =
            Metrics.newTimer(DynamicallyBoundFilterResource.class, "puts", TimeUnit.MILLISECONDS, TimeUnit.SECONDS);

    @POST
    public String echo(final String text) {
        final TimerContext timer = postTimer.time();
        try {
            return text;
        } finally {
            timer.stop();
        }
    }
View Full Code Here

        }
    }

    @PUT
    public void put(final String text) {
        final TimerContext timer = putTimer.time();
        timer.stop();
    }
View Full Code Here

        timer.stop();
    }

    @GET
    public String get() {
        final TimerContext timer = getTimer.time();
        try {
            return "text";
        } finally {
            timer.stop();
        }
    }
View Full Code Here

            compressedInput = loadAdj();

            if (!onlyAdjacency) loadEdata();
        }

        TimerContext _timer = loadVerticesTimers.time();

        if (compressedInput != null) {
            // This means we are using compressed data and cannot read in parallel (or could we?)
            // A bit ugly.
            index = new ArrayList<ShardIndex.IndexEntry>();
            index.add(new ShardIndex.IndexEntry(0, 0, 0));
        }
        final int sizeOf = (converter == null ? 0 : converter.sizeOf());

        /* Load in parallel */
        if (compressedInput == null) {
            final AtomicInteger countDown = new AtomicInteger(index.size());
            final Object waitLock = new Object();
            for(int chunk=0; chunk<index.size(); chunk++) {
                final int _chunk = chunk;
                parallelExecutor.submit(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            loadAdjChunk(windowStart, windowEnd, vertices, disableOutEdges, null, sizeOf, _chunk);
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                            throw new RuntimeException(ioe);
                        } finally {
                            countDown.decrementAndGet();
                            synchronized (waitLock) {
                                waitLock.notifyAll();
                            }

                        }
                    }
                } );
            }
            /* Wait for finishing */
            while (countDown.get() > 0) {
                synchronized (waitLock) {
                    try {
                        waitLock.wait(10000);
                    } catch (InterruptedException e) {}
                }
            }
        } else {
            loadAdjChunk(windowStart, windowEnd, vertices, disableOutEdges, compressedInput, sizeOf, 0);
        }

        _timer.stop();
    }
View Full Code Here

        index = new ShardIndex(new File(adjDataFilename)).sparserIndex(1204 * 1024);
        BufferedInputStream adjStream =  new BufferedInputStream(adjStreamRaw, (int) fileSizeEstimate /
                4);

        // Hack for cases when the load is not divided into subwindows
        TimerContext _timer = loadAdjTimer.time();

        ByteArrayOutputStream adjDataStream = new ByteArrayOutputStream((int) fileSizeEstimate);
        try {
            byte[] buf = new byte[(int) fileSizeEstimate / 4];   // Read in 16 chunks
            while (true) {
                int read =  adjStream.read(buf);
                if (read > 0) {
                    adjDataStream.write(buf, 0, read);
                } else break;
            }
        } catch (EOFException err) {
            // Done
        }

        adjData = adjDataStream.toByteArray();
        adjDataLength = adjData.length;

        adjStream.close();
        adjDataStream.close();

        _timer.stop();
        return null;
    }
View Full Code Here

                            logger.info("Load took: " + (System.currentTimeMillis() - t0) + "ms");
                        } else {
                            /* This is a mess! */
                            try {
                                long tf = System.currentTimeMillis();
                                final TimerContext _timer = waitForFutureTimer.time();
                                IntervalData next = nextWindow.get();

                                memoryShard = next.getMemShard();
                                _timer.stop();
                                logger.info("Waiting for future task loading took " + (System.currentTimeMillis() - tf) + " ms");
                                if (subIntervalStart != next.getSubInterval().getFirstVertex())
                                    throw new IllegalStateException("Future loaders interval does not match the expected one! " +
                                            subIntervalStart + " != " + next.getSubInterval().getFirstVertex());
                                subIntervalEnd = next.getSubInterval().getLastVertex();
View Full Code Here

    }

    private void execUpdates(final GraphChiProgram<VertexDataType, EdgeDataType> program,
                             final ChiVertex<VertexDataType, EdgeDataType>[] vertices) {
        if (vertices == null || vertices.length == 0) return;
        TimerContext _timer = executionTimer.time();
        if (Runtime.getRuntime().availableProcessors() == 1) {
            /* Sequential updates */
            for(ChiVertex<VertexDataType, EdgeDataType> vertex : vertices) {
                if (vertex != null) {
                    nupdates++;
                    program.update(vertex, chiContext);
                }
            }
        } else {
            final Object termlock = new Object();
            final int chunkSize = 1 + vertices.length / 64;

            final int nWorkers = vertices.length / chunkSize + 1;
            final AtomicInteger countDown = new AtomicInteger(1 + nWorkers);

            if (!enableDeterministicExecution) {
                for(ChiVertex<VertexDataType, EdgeDataType> vertex : vertices) {
                    if (vertex != null) vertex.parallelSafe = true;
                }
            }

            /* Parallel updates. One thread for non-parallel safe updates, others
     updated in parallel. This guarantees deterministic execution. */

            /* Non-safe updates */
            parallelExecutor.submit(new Runnable() {
                public void run() {
                    int thrupdates = 0;
                    GraphChiContext threadContext = chiContext.clone(0);
                    try {
                        for(ChiVertex<VertexDataType, EdgeDataType> vertex : vertices) {
                            if (vertex != null && !vertex.parallelSafe) {
                                thrupdates++;
                                program.update(vertex, threadContext);
                            }
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    finally {
                        int pending = countDown.decrementAndGet();
                        synchronized (termlock) {
                            nupdates += thrupdates;
                            if (pending == 0) {
                                termlock.notifyAll();;
                            }
                        }
                    }
                }
            });


            /* Parallel updates */
            for(int thrId = 0; thrId < nWorkers; thrId++) {
                final int myId = thrId;
                final int chunkStart = myId * chunkSize;
                final int chunkEnd = chunkStart + chunkSize;

                parallelExecutor.submit(new Runnable() {

                    public void run() {
                        int thrupdates = 0;
                        GraphChiContext threadContext = chiContext.clone(1 + myId);

                        try {
                            int end = chunkEnd;
                            if (end > vertices.length) end = vertices.length;
                            for(int i = chunkStart; i < end; i++) {
                                ChiVertex<VertexDataType, EdgeDataType> vertex = vertices[i];
                                if (vertex != null && vertex.parallelSafe) {
                                    thrupdates++;
                                    program.update(vertex, threadContext);
                                }
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            int pending = countDown.decrementAndGet();
                            synchronized (termlock) {
                                nupdates += thrupdates;
                                if (pending == 0) {
                                    termlock.notifyAll();
                                }
                            }
                        }
                    }
                });
            }
            synchronized (termlock) {
                while(countDown.get() > 0) {
                    try {
                        termlock.wait(1500);
                    } catch (InterruptedException e) {
                        // What to do?
                        e.printStackTrace();
                    }
                    if (countDown.get() > 0) logger.info("Waiting for execution to finish: countDown:" + countDown.get());
                }
            }

        }
        _timer.stop();
    }
View Full Code Here

        _timer.stop();
    }

    protected int initVertices(int nvertices, int firstVertexId, ChiVertex<VertexDataType, EdgeDataType>[] vertices) throws IOException
    {
        final TimerContext _timer = initVerticesTimer.time();
        ChiVertex.edgeValueConverter = edataConverter;
        ChiVertex.vertexValueConverter = vertexDataConverter;
        ChiVertex.blockManager = blockManager;

        int blockId = (vertexDataConverter != null ? vertexDataHandler.load(firstVertexId, firstVertexId + nvertices - 1) : -1);
        for(int j=0; j < nvertices; j++) {
            if (enableScheduler && !scheduler.isScheduled(j + firstVertexId)) {
                continue;
            }

            VertexDegree degree = degreeHandler.getDegree(j + firstVertexId);
            if (skipZeroDegreeVertices && (degree.inDegree + degree.outDegree == 0)) {
                continue;
            }

            ChiVertex<VertexDataType, EdgeDataType> v = new ChiVertex<VertexDataType, EdgeDataType>(j + firstVertexId, degree);

            if (vertexDataConverter != null) {
                v.setDataPtr(vertexDataHandler.getVertexValuePtr(j + firstVertexId, blockId));
            }
            vertices[j] = v;
        }


        _timer.stop();
        return blockId;
    }
View Full Code Here

TOP

Related Classes of com.yammer.metrics.core.TimerContext

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.