Examples of ElapsedTimer


Examples of gov.nasa.arc.mct.buffer.util.ElapsedTimer

    }

    @Override
    public Map<String, SortedMap<Long, Map<String, String>>> getData(Set<String> feedIDs, TimeUnit timeUnit, long startTime,
            long endTime) {
        final ElapsedTimer timer = new ElapsedTimer();
        timer.startInterval();
       
        Map<String, TreeMap<Long, Map<String, String>>> cachedData = getCachedData();
       
        Map<String, SortedMap<Long, Map<String, String>>> returnedData = new HashMap<String, SortedMap<Long, Map<String, String>>>();

        startTime = TimeUnit.NANOSECONDS.convert(startTime, timeUnit);
        endTime = TimeUnit.NANOSECONDS.convert(endTime, timeUnit);

        for (String feedID : feedIDs) {
            synchronized (this) {
                TreeMap<Long, Map<String, String>> feedCachedData = cachedData.get(feedID);
                if (feedCachedData == null) {
                    continue;
                }

                Map<Long, Map<String, String>> feedSearchedData = feedCachedData.subMap(startTime, true, endTime, true);
                if (feedSearchedData != null && !feedSearchedData.isEmpty()) {
                    SortedMap<Long, Map<String, String>> feedData = new TreeMap<Long, Map<String, String>>();
                    feedData.putAll(feedSearchedData);
                    returnedData.put(feedID, feedData);
                }
            }
        }
       
        timer.stopInterval();
        READ_PERF_LOGGER.debug("Time to get {} feeds from memory: {} from partition " + this.env.getCurrentBufferPartition(), feedIDs.size(), timer.getIntervalInMillis());

        return returnedData;
    }
View Full Code Here

Examples of gov.nasa.arc.mct.buffer.util.ElapsedTimer

        return cachedData == null;
    }

    @Override
    public Map<String, PartitionTimestamps> putData(Map<String, Map<Long, Map<String, String>>> value, TimeUnit timeUnit) {
        final ElapsedTimer timer = new ElapsedTimer();
        timer.startInterval();
       
        Map<String, PartitionTimestamps> timestamps = new HashMap<String, PartitionTimestamps>();
        Map<String, TreeMap<Long, Map<String, String>>> cachedData = getCachedData();

        for (Entry<String, Map<Long, Map<String, String>>> entry : value.entrySet()) {
            String feedID = entry.getKey();
            long largestTime = 0;
            long smallestTime = 0;
            synchronized (this) {
                TreeMap<Long, Map<String, String>> cachedFeedData = cachedData.get(feedID);
                if (cachedFeedData == null) {
                    cachedFeedData = new TreeMap<Long, Map<String, String>>(TIMESTAMP_COMPARATOR);
                    cachedData.put(feedID, cachedFeedData);
                }
                for (Entry<Long, Map<String, String>> feedData : entry.getValue().entrySet()) {
                    Long time = feedData.getKey();
                    time = TimeUnit.NANOSECONDS.convert(time, timeUnit);
                    LOGGER.debug("Putting data for feed {} with time {}", feedID, time);
                    if (time.longValue() > largestTime) {
                        largestTime = time.longValue();
                    }
                    if (smallestTime == 0) {
                        smallestTime = time.longValue();
                    } else if (time.longValue() < smallestTime) {
                        smallestTime = time.longValue();
                    }
                    Map<String, String> clonedFeedData = new HashMap<String, String>(feedData.getValue());
                    cachedFeedData.put(time, clonedFeedData);
                }
            }
            timestamps.put(feedID, new PartitionTimestamps(smallestTime, largestTime));
        }
       
       
        timer.stopInterval();
        WRITE_PERF_LOGGER.debug("Time to write {} feeds: {} from partition " + this.env.getCurrentBufferPartition(), value.size(), timer.getIntervalInMillis());

        return timestamps;
    }
View Full Code Here

Examples of gov.nasa.arc.mct.buffer.util.ElapsedTimer

        return timestamps;
    }
   
    @Override
    public void putData(Map<String, Map<Long, Map<String, String>>> value, TimeUnit timeUnit, MetaDataBuffer metadata, int metadataIndex) {
        final ElapsedTimer timer = new ElapsedTimer();
        timer.startInterval();
       
        Map<String, TreeMap<Long, Map<String, String>>> cachedData = getCachedData();

        for (Entry<String, Map<Long, Map<String, String>>> entry : value.entrySet()) {
            String feedID = entry.getKey();
            long largestTime = 0;
            long smallestTime = 0;
            synchronized (this) {
                TreeMap<Long, Map<String, String>> cachedFeedData = cachedData.get(feedID);
                if (cachedFeedData == null) {
                    cachedFeedData = new TreeMap<Long, Map<String, String>>(TIMESTAMP_COMPARATOR);
                    cachedData.put(feedID, cachedFeedData);
                }
                for (Entry<Long, Map<String, String>> feedData : entry.getValue().entrySet()) {
                    Long time = feedData.getKey();
                    time = TimeUnit.NANOSECONDS.convert(time, timeUnit);
                    LOGGER.debug("Putting data for feed {} with time {}", feedID, time);
                    if (time.longValue() > largestTime) {
                        largestTime = time.longValue();
                    }
                    if (smallestTime == 0) {
                        smallestTime = time.longValue();
                    } else if (time.longValue() < smallestTime) {
                        smallestTime = time.longValue();
                    }
                    Map<String, String> clonedFeedData = new HashMap<String, String>(feedData.getValue());
                    cachedFeedData.put(time, clonedFeedData);
                }
            }
            metadata.updatePartitionMetaData(metadataIndex, feedID, smallestTime, largestTime);
        }
       
       
        timer.stopInterval();
        if (WRITE_PERF_LOGGER.isDebugEnabled()) {
            WRITE_PERF_LOGGER.debug("Time to write {} feeds: {} from partition " + this.env.getCurrentBufferPartition(), value.size(), timer.getIntervalInMillis());
   
        }
    }
View Full Code Here

Examples of gov.nasa.arc.mct.buffer.util.ElapsedTimer

    }

    @Override
    public Map<String, List<Map<String, String>>> getData(Set<String> feedIDs, TimeUnit timeUnit, long startTime,
            long endTime) {
        final ElapsedTimer timer = new ElapsedTimer();
       
        feedIDs = new HashSet<String>(feedIDs);
        int feedSize = feedIDs.size();
        Map<String, List<Map<String, String>>> returnedData = new HashMap<String, List<Map<String,String>>>();
        for (DataProvider dataRetrieval : dataProviders) {
            timer.startInterval();

            Map<String, SortedMap<Long, Map<String, String>>> obtainedValues = dataRetrieval
                    .getData(feedIDs, startTime, endTime, timeUnit);
           
            for (Entry<String, SortedMap<Long, Map<String, String>>> entry: obtainedValues.entrySet()) {
                returnedData.put(entry.getKey(), new LinkedList<Map<String,String>>(entry.getValue().values()));
            }
            filterObtainedFeeds(dataRetrieval, feedIDs, obtainedValues, timeUnit, startTime);
           
            timer.stopInterval();
            READ_PERF_LOGGER.debug("Time to get {} feeds: {} ms from provider " + dataRetrieval.getLOS(), feedSize, timer.getIntervalInMillis());

            if (feedIDs.isEmpty()) { break; }
        }
        return returnedData;
    }
View Full Code Here

Examples of gov.nasa.arc.mct.util.internal.ElapsedTimer

   
    protected class NodeViewManifestationListener extends AbstractViewListener {
       
        @Override
        public void actionPerformed(TreeExpansionEvent event) {
            final ElapsedTimer timer = new ElapsedTimer();
            timer.startInterval();
           
            JTree tree = (JTree) event.getSource();
            final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();

            final MCTMutableTreeNode selectedNode = node;

            AbstractComponent component = getManifestedComponent();

            for (AbstractComponent childComponent : component.getComponents()) {
                Set<ViewInfo> nodeViews = childComponent.getViewInfos(ViewType.NODE);
                if (!nodeViews.isEmpty()) {
                    ViewInfo nextViewInfo = nodeViews.iterator().next();
                   
                    // Children are only allowed if the component is not a leaf or the component is another users drop box
                    boolean allowsChildren =!childComponent.isLeaf();
                   
                    View childNodeView = nextViewInfo.createView(childComponent);
                    MCTMutableTreeNode childNode = new MCTMutableTreeNode(childNodeView, tree, allowsChildren);

                    if (allowsChildren){
                        MCTMutableTreeNode grandChildNode = new MCTMutableTreeNode(View.NULL_VIEW_MANIFESTATION, tree);
                        childNode.add(grandChildNode);
                        childNode.setProxy(true);
                    }
                    selectedNode.add(childNode);
                    childNodeView.addPropertyChangeListener(VIEW_STALE_PROPERTY, objectStaleListener);
                }
            }
            treeModel.reload(selectedNode);
           
            timer.stopInterval();
            PERF_LOGGER.debug("Time to expand node {}: {}", component.getId(), timer.getIntervalInMillis());
        }
View Full Code Here

Examples of gov.nasa.arc.mct.util.internal.ElapsedTimer

  public ExecutionResult execute(String categoryKey, PolicyContext context) {
    ExecutionResult result; 
    List<Policy> list = map.get(categoryKey);
    if (list == null)
      return new ExecutionResult(context, true, "No policies registered for " + categoryKey);
    ElapsedTimer categoryTimer = new ElapsedTimer();
    categoryTimer.startInterval();
    for (Policy policy : list) {
      ElapsedTimer policyTimer = new ElapsedTimer();
      policyTimer.startInterval();
      result = policy.execute(context);
      policyTimer.stopInterval();
      PERF_LOGGER.debug("time to execute policy {0} {1}", policy.getClass().getName(), policyTimer.getIntervalInMillis());
      if (!result.getStatus()) {
        LOGGER.debug("Policy category {} failed on policy {}", categoryKey, policy.getClass().getName());
        return result;
      }
    }
View Full Code Here

Examples of gov.nasa.arc.mct.util.internal.ElapsedTimer

   
   
    @BeforeMethod
    public void setup() {
        time = 1;
        timer = new ElapsedTimer() {
            @Override
            long getCurrentTime() {
                return time;
            }
        };
View Full Code Here

Examples of org.apache.jcs.utils.timing.ElapsedTimer

        int runs = 1000;
        int upperKB = 50;

        JCS jcs = JCS.getInstance( ( numPerRun / 2 ) + "aSecond" );

        ElapsedTimer timer = new ElapsedTimer();
        int numToGet = numPerRun * ( runs / 10 );
        for ( int i = 0; i < numToGet; i++ )
        {
            jcs.get( String.valueOf( i ) );
        }
        System.out.println( LOG_DIVIDER );
        System.out.println( "After getting " + numToGet );
        System.out.println( "Elapsed " + timer.getElapsedTimeString() );
        logMemoryUsage();

        jcs.clear();
        Thread.sleep( 3000 );
        System.out.println( LOG_DIVIDER );
        System.out.println( "Start putting" );

        long totalSize = 0;
        int totalPut = 0;

        Random random = new Random( 89 );
        while ( runCount < runs )
        {
            runCount++;
            for ( int i = 0; i < numPerRun; i++ )
            {
                // 1/2 upper to upperKB-4 KB
                int kiloBytes = Math.max( upperKB / 2, random.nextInt( upperKB ) );
                int bytes = ( kiloBytes ) * 1024;
                totalSize += bytes;
                totalPut++;
                DiskTestObject object = new DiskTestObject( new Integer( i ), new byte[bytes] );
                jcs.put( String.valueOf( totalPut ), object );
            }

            // remove half of those inserted the previous run
            if ( runCount > 1 )
            {
                for ( int j = ( ( totalPut - numPerRun ) - ( numPerRun / 2 ) ); j < ( totalPut - numPerRun ); j++ )
                {
                    jcs.remove( String.valueOf( j ) );
                }
            }

            Thread.sleep( pauseBetweenRuns );
            if ( runCount % 1 == 0 )
            {
                System.out.println( LOG_DIVIDER );
                System.out.println( "Elapsed " + timer.getElapsedTimeString() );
                System.out.println( "Run count: " + runCount + " Average size: " + ( totalSize / totalPut ) + "\n"
                    + jcs.getStats() );
                logMemoryUsage();
            }
        }
View Full Code Here

Examples of org.apache.jcs.utils.timing.ElapsedTimer

     *            data overlap
     * @return <code>true</code> if the test passes
     */
    private boolean checkKeyDataConsistency( boolean checkForDedOverlaps )
    {
        ElapsedTimer timer = new ElapsedTimer();
        log.debug( logCacheName + "Performing inital consistency check" );

        boolean isOk = true;
        long fileLength = 0;
        try
        {
            fileLength = dataFile.length();

            Iterator itr = keyHash.entrySet().iterator();
            while ( itr.hasNext() )
            {
                Map.Entry e = (Map.Entry) itr.next();
                IndexedDiskElementDescriptor ded = (IndexedDiskElementDescriptor) e.getValue();

                isOk = ( ded.pos + IndexedDisk.RECORD_HEADER + ded.len <= fileLength );

                if ( !isOk )
                {
                    log.warn( logCacheName + "The dataFile is corrupted!" + "\n raf.length() = " + fileLength
                        + "\n ded.pos = " + ded.pos );
                    break;
                }
            }

            if ( isOk && checkForDedOverlaps )
            {
                isOk = checkForDedOverlaps( createPositionSortedDescriptorList() );
            }
        }
        catch ( Exception e )
        {
            log.error( e );
            isOk = false;
        }

        if ( log.isInfoEnabled() )
        {
            log.info( logCacheName + "Finished inital consistency check, isOk = " + isOk + " in "
                + timer.getElapsedTimeString() );
        }

        return isOk;
    }
View Full Code Here

Examples of org.apache.jcs.utils.timing.ElapsedTimer

     * <li>Restore system to standard operation.</li>
     * </ol>
     */
    protected void optimizeFile()
    {
        ElapsedTimer timer = new ElapsedTimer();
        timesOptimized++;
        if ( log.isInfoEnabled() )
        {
            log.info( logCacheName + "Beginning Optimization #" + timesOptimized );
        }

        // CREATE SNAPSHOT
        IndexedDiskElementDescriptor[] defragList = null;
        try
        {
            storageLock.writeLock().acquire();
            queueInput = true;
            // shut off recycle while we're optimizing,
            doRecycle = false;
            defragList = createPositionSortedDescriptorList();
            // Release iff I aquired.
            storageLock.writeLock().release();
        }
        catch ( InterruptedException e )
        {
            log.error( logCacheName + "Error setting up optimization.", e );
            return;
        }

        // Defrag the file outside of the write lock. This allows a move to be made,
        // and yet have the element still accessible for reading or writing.
        long expectedNextPos = defragFile( defragList, 0 );

        // ADD THE QUEUED ITEMS to the end and then truncate
        try
        {
            storageLock.writeLock().acquire();

            if ( !queuedPutList.isEmpty() )
            {
                // This is perhaps unecessary, but the list might not be as sorted as we think.
                defragList = new IndexedDiskElementDescriptor[queuedPutList.size()];
                queuedPutList.toArray( defragList );
                Arrays.sort( defragList, new PositionComparator() );

                // pack them at the end
                expectedNextPos = defragFile( defragList, expectedNextPos );
            }
            // TRUNCATE THE FILE
            dataFile.truncate( expectedNextPos );
        }
        catch ( Exception e )
        {
            log.error( logCacheName + "Error optimizing queued puts.", e );
        }
        finally
        {
            // RESTORE NORMAL OPERATION
            removeCount = 0;
            bytesFree = 0;
            initRecycleBin();
            queuedPutList.clear();
            queueInput = false;
            // turn recycle back on.
            doRecycle = true;
            isOptimizing = false;

            storageLock.writeLock().release();
        }

        if ( log.isInfoEnabled() )
        {
            log.info( logCacheName + "Finished #" + timesOptimized + " Optimization took "
                + timer.getElapsedTimeString() );
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.