Package edu.brown.profilers

Examples of edu.brown.profilers.ProfileMeasurement


                   
                    // Change the current state
                    cmp.m_controlState = ControlState.PAUSED;
                   
                    // Then tell the client to drain
                    ProfileMeasurement pm = new ProfileMeasurement();
                    try {
                        if (debug.val) LOG.debug("Draining connection queue for client " + cmp.getClientId());
                        pm.start();
                        cmp.getClientHandle().drain();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        pm.stop();
                        if (debug.val) LOG.debug("Drain Queue Time: " + ProfileMeasurementUtil.debug(pm));
                    }
                    break;
                }
                case SHUTDOWN: {
View Full Code Here


            } // FOR
        }

        final PartitionEstimator p_estimator = new PartitionEstimator(args.catalogContext);
        final MarkovCostModel thread_costmodels[][] = new MarkovCostModel[num_threads][num_partitions];
        final ProfileMeasurement profilers[] = new ProfileMeasurement[num_threads];
        final LinkedBlockingDeque<Pair<Integer, TransactionTrace>> queues[] = (LinkedBlockingDeque<Pair<Integer, TransactionTrace>>[]) new LinkedBlockingDeque<?>[num_threads];
        for (int i = 0; i < num_threads; i++) {
            profilers[i] = new ProfileMeasurement("ESTIMATION");
            queues[i] = new LinkedBlockingDeque<Pair<Integer, TransactionTrace>>();
        } // FOR
        LOG.info(String.format("Estimating the accuracy of the MarkovGraphs using %d transactions [threads=%d]", args.workload.getTransactionCount(), num_threads));
        LOG.info("THRESHOLDS: " + args.thresholds);

        // QUEUING THREAD
        final AtomicBoolean queued_all = new AtomicBoolean(false);
        runnables.add(new Runnable() {
            @Override
            public void run() {
                List<TransactionTrace> all_txns = new ArrayList<TransactionTrace>(args.workload.getTransactions());
                Collections.shuffle(all_txns);
                int ctr = 0;
                for (TransactionTrace txn_trace : all_txns) {
                    // Make sure it goes to the right base partition
                    int partition = HStoreConstants.NULL_PARTITION_ID;
                    try {
                        partition = p_estimator.getBasePartition(txn_trace);
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                    assert(partition != HStoreConstants.NULL_PARTITION_ID) : "Failed to get base partition for " + txn_trace + "\n" + txn_trace.debug(args.catalog_db);
                    if (base_partition != HStoreConstants.NULL_PARTITION_ID && base_partition != partition)
                        continue;

                    int queue_idx = (global ? ctr : partition) % num_threads;
                    queues[queue_idx].add(Pair.of(partition, txn_trace));
                    if (++ctr % marker == 0)
                        LOG.info(String.format("Queued %d/%d transactions", ctr, num_transactions));
                } // FOR
                queued_all.set(true);

                // Poke all our threads just in case they finished
                for (Thread t : processing_threads)
                    t.interrupt();
            }
        });

        // PROCESSING THREADS
        for (int i = 0; i < num_threads; i++) {
            final int thread_id = i;
            runnables.add(new Runnable() {
                @Override
                public void run() {
                    Thread self = Thread.currentThread();
                    processing_threads.add(self);

                    Pair<Integer, TransactionTrace> pair = null;
                    final Set<MarkovOptimization> penalty_groups = new HashSet<MarkovOptimization>();
                    final Set<Penalty> penalties = new HashSet<Penalty>();
                    ObjectHistogram<MarkovOptimization> proc_h = null;

                    ProfileMeasurement profiler = profilers[thread_id];
                    assert (profiler != null);

                    MarkovCostModel costmodels[] = thread_costmodels[thread_id];
                    for (int p = 0; p < num_partitions; p++) {
                        MarkovGraphsContainer markovs = (global ? thread_markovs[thread_id].get(MarkovUtil.GLOBAL_MARKOV_CONTAINER_ID) : thread_markovs[thread_id].get(p));
                        MarkovEstimator t_estimator = new MarkovEstimator(args.catalogContext, p_estimator, markovs);
                        costmodels[p] = new MarkovCostModel(args.catalogContext, p_estimator, t_estimator, args.thresholds);
                        if (force_fullpath)
                            thread_costmodels[thread_id][p].forceFullPathComparison();
                        if (force_regenerate)
                            thread_costmodels[thread_id][p].forceRegenerateMarkovEstimates();
                    } // FOR

                    int thread_ctr = 0;
                    while (true) {
                        try {
                            if (queued_all.get()) {
                                pair = queues[thread_id].poll();
                            } else {
                                pair = queues[thread_id].take();

                                // Steal work
                                if (pair == null) {
                                    for (int i = 0; i < num_threads; i++) {
                                        if (i == thread_id)
                                            continue;
                                        pair = queues[i].take();
                                        if (pair != null)
                                            break;
                                    } // FOR
                                }
                            }
                        } catch (InterruptedException ex) {
                            continue;
                        }
                        if (pair == null)
                            break;

                        int partition = pair.getFirst();
                        TransactionTrace txn_trace = pair.getSecond();
                        Procedure catalog_proc = txn_trace.getCatalogItem(args.catalog_db);
                        total_h.put(catalog_proc);
                        if (debug.val)
                            LOG.debug(String.format("Processing %s [%d / %d]", txn_trace, thread_ctr, thread_ctr + queues[thread_id].size()));

                        proc_h = proc_penalties_h.get(catalog_proc);
                        if (proc_h == null) {
                            synchronized (proc_penalties_h) {
                                proc_h = proc_penalties_h.get(catalog_proc);
                                if (proc_h == null) {
                                    proc_h = new ObjectHistogram<MarkovOptimization>();
                                    proc_penalties_h.put(catalog_proc, proc_h);
                                }
                            } // SYNCH
                        }

                        double cost = 0.0d;
                        Throwable error = null;
                        try {
                            profiler.start();
                            if (skip_processing == false) {
                                cost = costmodels[partition].estimateTransactionCost(args.catalogContext, txn_trace);
                            }
                        } catch (Throwable ex) {
                            error = ex;
                        } finally {
                            profiler.stop();
                        }
                        if (error != null) {
                            failures.getAndIncrement();
                            String msg = "Failed to estimate transaction cost for " + txn_trace;
                            if (stop_on_error)
                                throw new RuntimeException(msg, error);
                            LOG.warn(msg, error);
                            continue;
                        }

                        if (cost > 0) {
                            penalty_groups.clear();
                            penalties.clear();
                            for (Penalty p : costmodels[partition].getLastPenalties()) {
                                penalty_groups.add(p.getGroup());
                                penalties.add(p);
                            } // FOR
                            proc_h.put(penalty_groups);
                            optimizations_h.put(penalty_groups);
                            penalties_h.put(penalties);
                            missed_h.put(catalog_proc);
                        } else {
                            accurate_h.put(catalog_proc);
                        }
                        int global_ctr = total.incrementAndGet();
                        if (global_ctr % marker == 0)
                            LOG.info(String.format("Processed %d/%d transactions %s", global_ctr, num_transactions, (failures.get() > 0 ? String.format("[failures=%d]", failures.get()) : "")));
                        thread_ctr++;
                    } // WHILE
                    LOG.info(String.format("Processing Thread Finished %d / %d", thread_finished.incrementAndGet(), num_threads));
                }
            });
        } // FOR
        ThreadUtil.runGlobalPool(runnables);

        Map<Object, String> debugLabels = CatalogUtil.getHistogramLabels(args.catalog_db.getProcedures());

        ObjectHistogram<Procedure> fastpath_h = new ObjectHistogram<Procedure>();
        fastpath_h.setDebugLabels(debugLabels);
        ObjectHistogram<Procedure> fullpath_h = new ObjectHistogram<Procedure>();
        fullpath_h.setDebugLabels(debugLabels);
        ProfileMeasurement total_time = new ProfileMeasurement("ESTIMATION");

        for (int i = 0; i < num_threads; i++) {
            for (int p = 0; p < num_partitions; p++) {
                MarkovCostModel mc = thread_costmodels[i][p];
                fastpath_h.put(mc.fast_path_counter);
                fullpath_h.put(mc.full_path_counter);
                total_time.appendTime(profilers[i]);
            }
        } // FOR

        int accurate_cnt = total.get() - (int) missed_h.getSampleCount();
        assert (accurate_cnt == accurate_h.getSampleCount());

        // ---------------------------------------------------------------------------------------------

        Map<String, Object> m0 = new ListOrderedMap<String, Object>();
        m0.put("PARTITIONS", num_partitions);
        m0.put("FORCE FULLPATH", force_fullpath);
        m0.put("FORCE REGENERATE", force_regenerate);
        m0.put("COMPUTATION TIME", String.format("%.2f ms total / %.2f ms avg", total_time.getTotalThinkTimeMS(), total_time.getAverageThinkTimeMS()));
        m0.put("TRANSACTION COUNTS", total_h.setDebugLabels(debugLabels));

        Map<String, Object> m1 = new ListOrderedMap<String, Object>();
        m1.put("ACCURATE TRANSACTIONS", accurate_h.setDebugLabels(debugLabels));
        m1.put("MISSED TRANSACTIONS", missed_h.setDebugLabels(debugLabels));
View Full Code Here

        // XXX: 2011-10-28
        costmodel.setCachingEnabled(true);
        ObjectHistogram<String> hist = new ObjectHistogram<String>();
        for (int i = 0; i < 2; i++) {
            ProfileMeasurement time = new ProfileMeasurement("costmodel").start();
            hist.clear();
            for (AbstractTraceElement<? extends CatalogType> element : args.workload) {
                if (element instanceof TransactionTrace) {
                    total++;
                    TransactionTrace xact = (TransactionTrace) element;
                    boolean is_singlesited = costmodel.processTransaction(args.catalogContext, xact, null).singlesited;
                    if (is_singlesited) {
                        singlepartition++;
                        hist.put(xact.getCatalogItemName());
                    } else {
                        multipartition++;
                        if (!hist.contains(xact.getCatalogItemName()))
                            hist.put(xact.getCatalogItemName(), 0);
                    }
                }
            } // FOR
            System.err.println("ESTIMATE TIME: " + time.stop().getTotalThinkTimeSeconds());
            break; // XXX
        } // FOR
        // long total_partitions_touched_txns =
        // costmodel.getTxnPartitionAccessHistogram().getSampleCount();
        // long total_partitions_touched_queries =
View Full Code Here

        if (debug.val) LOG.debug("Collecting BatchPlanner stats for " + proc.getName());
       
        // We're going to create a new profiler that we can use
        // to add up all of the values from the individual BatchPlannerProfilers
        BatchPlannerProfiler total = new BatchPlannerProfiler();
        ProfileMeasurement totalPMs[] = total.getProfileMeasurements();
       
        // Find all of the BatchPlanners for each partition for our target procedure
        Collection<BatchPlanner> planners = this.getBatchPlanners(proc);
        for (BatchPlanner planner : planners) {
            BatchPlannerProfiler profiler = planner.getDebugContext().getProfiler();
            if (profiler == null) continue;
           
            ProfileMeasurement profilerPMs[] = profiler.getProfileMeasurements();
            assert(totalPMs.length == profilerPMs.length);
            for (int i = 0; i < totalPMs.length; i++) {
                totalPMs[i].appendTime(profilerPMs[i]);
            } // FOR
           
View Full Code Here

            rowValues[offset++] = pm.getTotalThinkTime();
            rowValues[offset++] = pm.getInvocations();
        } // FOR
       
        // ThrottlingQueue
        ProfileMeasurement throttlePM = initQueue.getThrottleTime();
        rowValues[offset++] = throttlePM.getTotalThinkTime();
        rowValues[offset++] = throttlePM.getInvocations();
       
        // PartitionLockQueue
        rowValues[offset++] = MathUtil.weightedMean(initProfiler.waitTimes);
        for (ProfileMeasurement pm : initProfiler.queueStates.values()) {
            rowValues[offset++] = pm.getTotalThinkTime();
View Full Code Here

    /**
     *
     * @return
     */
    private Map<String, Object> siteInfo() {
        ProfileMeasurement pm = null;
        String value = null;
       
        Map<String, Object> siteInfo = new LinkedHashMap<String, Object>();
        if (TransactionCounter.COMPLETED.get() > 0) {
            siteInfo.put("Completed Txns", TransactionCounter.COMPLETED.get());
        }
       
        // ClientInterface
        ClientInterface ci = hstore_site.getClientInterface();
        if (ci != null) {
            siteInfo.put("# of Connections", ci.getConnectionCount());
           
            value = String.format("%d txns [limit=%d, release=%d] / " +
                              "%d bytes [limit=%d, release=%d]%s",
                                  ci.getPendingTxnCount(),
                                  ci.getMaxPendingTxnCount(),
                                  ci.getReleasePendingTxnCount(),
                                  ci.getPendingTxnBytes(),
                                  ci.getMaxPendingTxnBytes(),
                                  ci.getReleasePendingTxnBytes(),
                                  (ci.hasBackPressure() ? " / *THROTTLED*" : ""));
            siteInfo.put("Client Interface Queue", value);
            siteInfo.put("BackPressure Counter", ci.getBackPressureCount());
        }
       
        if (hstore_conf.site.profiling && hstore_site.getProfiler() != null) {
            // Compute the approximate arrival rate of transaction
            // requests per second from clients
            HStoreSiteProfiler profiler = hstore_site.getProfiler();
           
            pm = profiler.network_processing;
            double totalTime = System.currentTimeMillis() - startTime;
            double arrivalRate = (totalTime > 0 ? (pm.getInvocations() / totalTime) : 0d);
           
            value = String.format("%.02f txn/sec [total=%d]", arrivalRate, pm.getInvocations());
            siteInfo.put("Arrival Rate", value);
           
            pm = profiler.network_backup_off;
            siteInfo.put("Back Pressure Off", ProfileMeasurementUtil.formatComparison(pm, null, true));
           
            pm = profiler.network_backup_on;
            siteInfo.put("Back Pressure On", ProfileMeasurementUtil.formatComparison(pm, null, true));
        }

       
        // TransactionQueueManager
        TransactionQueueManager queueManager = hstore_site.getTransactionQueueManager();
        TransactionQueueManager.Debug queueManagerDebug = queueManager.getDebugContext();
       
        int inflight_cur = siteDebug.getInflightTxnCount();
        if (inflight_cur < this.inflight_min && inflight_cur > 0) this.inflight_min = inflight_cur;
        if (inflight_cur > this.inflight_max) this.inflight_max = inflight_cur;
       
        // CommandLogWriter
        int inflight_cmdlog = 0;
        CommandLogWriter cmdLogger = hstore_site.getCommandLogWriter();
        if (cmdLogger != null) {
            inflight_cmdlog = cmdLogger.getTotalTxnCount();
        }
       
        siteInfo.put("InFlight Txns",
                      String.format("%d total / %d init / %d queued / %d restart / %d cmdlog / %d deletable " +
                                "[totalMin=%d, totalMax=%d]",
                                    inflight_cur,       // total
                                    queueManagerDebug.getInitQueueSize(), // init
                                    queueManagerDebug.getLockQueueSize(), // queued
                                    queueManagerDebug.getRestartQueueSize(), // restart
                                    inflight_cmdlog,    // cmdlog
                                    this.siteDebug.getDeletableTxnCount(), // deletable
                                    this.inflight_min,  // totalMin
                                    this.inflight_max   // totalMax
        ));
       
       
        if (hstore_conf.site.status_check_for_zombies) {
            this.zombieInfo(siteInfo);
        }
       
        if (hstore_conf.site.profiling) {
            HStoreSiteProfiler profiler = this.hstore_site.getProfiler();
            pm = profiler.network_idle;
            value = ProfileMeasurementUtil.formatComparison(pm, this.lastNetworkIdle, true);
            siteInfo.put("Network Idle", value);
            this.lastNetworkIdle = new ProfileMeasurement(pm);
           
            pm = profiler.network_processing;
            value = ProfileMeasurementUtil.formatComparison(pm, this.lastNetworkProcessing, true);
            siteInfo.put("Network Processing", value);
            this.lastNetworkProcessing = new ProfileMeasurement(pm);
        }
       
        if (hstore_conf.site.exec_postprocessing_threads) {
            int processing_cur = siteDebug.getQueuedResponseCount();
            if (processing_min == null || processing_cur < processing_min) processing_min = processing_cur;
            if (processing_max == null || processing_cur > processing_max) processing_max = processing_cur;
           
            String val = String.format("%-5d [min=%d, max=%d]", processing_cur, processing_min, processing_max);
            int i = 0;
            for (TransactionPostProcessor tpp : hstore_site.getTransactionPostProcessors()) {
                pm = tpp.getExecTime();
                if (pm != null) {
                    val += String.format("\n[%02d] %d total / %.2fms total / %.2fms avg",
                                         i++,
                                         pm.getInvocations(),
                                         pm.getTotalThinkTimeMS(),
                                         pm.getAverageThinkTimeMS());
                }
            } // FOR
           
            siteInfo.put("Post-Processing Txns", val);
        }
View Full Code Here

                invokedTxns.put(partition, (int)profiler.txn_time.getInvocations());
               
                AbstractProfiler profilers[] = { profiler, lastProfiler, nextProfiler, total };
                for (ProfileMeasurement pm : profilers[0].getProfileMeasurements()) {
                    String name = pm.getName();
                    ProfileMeasurement inner[] = new ProfileMeasurement[profilers.length];
                    for (int i = 0; i < profilers.length; i++) {
                        if (profilers[i] != null) {
                            inner[i] = (i == 0 ? pm : profilers[i].getProfileMeasurement(name));
                        }
                    } // FOR
View Full Code Here

            if (executor == null) continue;
            PartitionExecutor.Debug dbg = executor.getDebugContext();
            bps.addAll(dbg.getBatchPlanners());
        } // FOR
        Map<Procedure, ProfileMeasurement[]> proc_totals = new HashMap<Procedure, ProfileMeasurement[]>();
        ProfileMeasurement final_totals[] = null;
        int num_cols = 0;
        for (BatchPlanner bp : bps) {
            ProfileMeasurement times[] = bp.getDebugContext().getProfiler().getProfileMeasurements();
           
            Procedure catalog_proc = bp.getProcedure();
            ProfileMeasurement totals[] = proc_totals.get(catalog_proc);
            if (totals == null) {
                num_cols = times.length+2;
                totals = new ProfileMeasurement[num_cols-1];
                final_totals = new ProfileMeasurement[num_cols-1];
                proc_totals.put(catalog_proc, totals);
            }
            for (int i = 0; i < totals.length; i++) {
                if (i == 0) {
                    if (totals[i] == null) totals[i] = new ProfileMeasurement("total");
                } else {
                    if (totals[i] == null)
                        totals[i] = new ProfileMeasurement(times[i-1]);
                    else
                        totals[i].appendTime(times[i-1]);
                    totals[0].appendTime(times[i-1]);
                }
                if (final_totals[i] == null) final_totals[i] = new ProfileMeasurement(totals[i].getName());
            } // FOR
        } // FOR
        if (proc_totals.isEmpty()) return (null);
       
        boolean first = true;
        String header[] = new String[num_cols];
        Object rows[][] = new String[proc_totals.size()+2][];
        String col_delimiters[] = new String[num_cols];
        String row_delimiters[] = new String[rows.length];
        int i = -1;
        int j = 0;
        for (Procedure proc : proc_totals.keySet()) {
            j = 0;
            rows[++i] = new String[num_cols];
            rows[i][j++] = proc.getName();
            if (first) header[0] = "";
            for (ProfileMeasurement pm : proc_totals.get(proc)) {
                if (first) header[j] = pm.getName();
                final_totals[j-1].appendTime(pm);
                rows[i][j] = Long.toString(Math.round(pm.getTotalThinkTimeMS()));
                j++;
            } // FOR
            first = false;
        } // FOR
       
        j = 0;
        rows[++i] = new String[num_cols];
        rows[i+1] = new String[num_cols];
        rows[i][j++] = "TOTAL";
        row_delimiters[i] = "-"; // "\u2015";

        for (int final_idx = 0; final_idx < final_totals.length; final_idx++) {
            if (final_idx == 0) col_delimiters[j] = " | ";
           
            ProfileMeasurement pm = final_totals[final_idx];
            rows[i][j] = Long.toString(Math.round(pm.getTotalThinkTimeMS()));
            rows[i+1][j] = (final_idx > 0 ? String.format("%.3f", pm.getTotalThinkTimeMS() / final_totals[0].getTotalThinkTimeMS()) : "");
            j++;
        } // FOR
       
//        if (debug.val) {
//            for (i = 0; i < rows.length; i++) {
View Full Code Here

     *
     * @param catalog_db
     */
    private void initTxnProfileInfo(Database catalog_db) {
        TransactionProfiler profiler = new TransactionProfiler();
        ProfileMeasurement fields[] = profiler.getProfileMeasurements();
       
        // COLUMN DELIMITERS
        String last_prefix = null;
        String col_delimiters[] = new String[fields.length*2 + 2];
        int col_idx = 0;
View Full Code Here

TOP

Related Classes of edu.brown.profilers.ProfileMeasurement

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.