Search in sources :

Example 1 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class TestLocalFileSystem method testStatistics.

@Test(timeout = 1000)
public void testStatistics() throws Exception {
    int fileSchemeCount = 0;
    for (Statistics stats : FileSystem.getAllStatistics()) {
        if (stats.getScheme().equals("file")) {
            fileSchemeCount++;
        }
    }
    assertEquals(1, fileSchemeCount);
}
Also used : Statistics(org.apache.hadoop.fs.FileSystem.Statistics) Test(org.junit.Test)

Example 2 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class AbstractFileSystem method getAllStatistics.

protected static synchronized Map<URI, Statistics> getAllStatistics() {
    Map<URI, Statistics> statsMap = new HashMap<URI, Statistics>(STATISTICS_TABLE.size());
    for (Map.Entry<URI, Statistics> pair : STATISTICS_TABLE.entrySet()) {
        URI key = pair.getKey();
        Statistics value = pair.getValue();
        Statistics newStatsObj = new Statistics(value);
        statsMap.put(URI.create(key.toString()), newStatsObj);
    }
    return statsMap;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) URI(java.net.URI) Statistics(org.apache.hadoop.fs.FileSystem.Statistics) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class FCStatisticsBaseTest method testStatisticsThreadLocalDataCleanUp.

@Test(timeout = 70000)
public void testStatisticsThreadLocalDataCleanUp() throws Exception {
    final Statistics stats = new Statistics("test");
    // create a small thread pool to test the statistics
    final int size = 2;
    ExecutorService es = Executors.newFixedThreadPool(size);
    List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>(size);
    for (int i = 0; i < size; i++) {
        tasks.add(new Callable<Boolean>() {

            public Boolean call() {
                // this populates the data set in statistics
                stats.incrementReadOps(1);
                return true;
            }
        });
    }
    // run the threads
    es.invokeAll(tasks);
    // assert that the data size is exactly the number of threads
    final AtomicInteger allDataSize = new AtomicInteger(0);
    allDataSize.set(stats.getAllThreadLocalDataSize());
    Assert.assertEquals(size, allDataSize.get());
    Assert.assertEquals(size, stats.getReadOps());
    // force the GC to collect the threads by shutting down the thread pool
    es.shutdownNow();
    es.awaitTermination(1, TimeUnit.MINUTES);
    es = null;
    // force GC to garbage collect threads
    System.gc();
    // wait for up to 60 seconds
    GenericTestUtils.waitFor(new Supplier<Boolean>() {

        @Override
        public Boolean get() {
            int size = stats.getAllThreadLocalDataSize();
            allDataSize.set(size);
            if (size == 0) {
                return true;
            }
            LOG.warn("not all references have been cleaned up; still " + allDataSize.get() + " references left");
            LOG.warn("triggering another GC");
            System.gc();
            return false;
        }
    }, 500, 60 * 1000);
    Assert.assertEquals(0, allDataSize.get());
    Assert.assertEquals(size, stats.getReadOps());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Statistics(org.apache.hadoop.fs.FileSystem.Statistics) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 4 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class Task method updateCounters.

private synchronized void updateCounters() {
    Map<String, List<FileSystem.Statistics>> map = new HashMap<String, List<FileSystem.Statistics>>();
    for (Statistics stat : FileSystem.getAllStatistics()) {
        String uriScheme = stat.getScheme();
        if (map.containsKey(uriScheme)) {
            List<FileSystem.Statistics> list = map.get(uriScheme);
            list.add(stat);
        } else {
            List<FileSystem.Statistics> list = new ArrayList<FileSystem.Statistics>();
            list.add(stat);
            map.put(uriScheme, list);
        }
    }
    for (Map.Entry<String, List<FileSystem.Statistics>> entry : map.entrySet()) {
        FileSystemStatisticUpdater updater = statisticUpdaters.get(entry.getKey());
        if (updater == null) {
            //new FileSystem has been found in the cache
            updater = new FileSystemStatisticUpdater(entry.getValue(), entry.getKey());
            statisticUpdaters.put(entry.getKey(), updater);
        }
        updater.updateCounters();
    }
    gcUpdater.incrementGcCounter();
    updateResourceCounters();
}
Also used : HashMap(java.util.HashMap) FileSystem(org.apache.hadoop.fs.FileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Statistics(org.apache.hadoop.fs.FileSystem.Statistics) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class FCStatisticsBaseTest method testStatisticsOperations.

@Test(timeout = 60000)
public void testStatisticsOperations() throws Exception {
    final Statistics stats = new Statistics("file");
    Assert.assertEquals(0L, stats.getBytesRead());
    Assert.assertEquals(0L, stats.getBytesWritten());
    Assert.assertEquals(0, stats.getWriteOps());
    stats.incrementBytesWritten(1000);
    Assert.assertEquals(1000L, stats.getBytesWritten());
    Assert.assertEquals(0, stats.getWriteOps());
    stats.incrementWriteOps(123);
    Assert.assertEquals(123, stats.getWriteOps());
    Thread thread = new Thread() {

        @Override
        public void run() {
            stats.incrementWriteOps(1);
        }
    };
    thread.start();
    Uninterruptibles.joinUninterruptibly(thread);
    Assert.assertEquals(124, stats.getWriteOps());
    // Test copy constructor and reset function
    Statistics stats2 = new Statistics(stats);
    stats.reset();
    Assert.assertEquals(0, stats.getWriteOps());
    Assert.assertEquals(0L, stats.getBytesWritten());
    Assert.assertEquals(0L, stats.getBytesRead());
    Assert.assertEquals(124, stats2.getWriteOps());
    Assert.assertEquals(1000L, stats2.getBytesWritten());
    Assert.assertEquals(0L, stats2.getBytesRead());
}
Also used : Statistics(org.apache.hadoop.fs.FileSystem.Statistics) Test(org.junit.Test)

Aggregations

Statistics (org.apache.hadoop.fs.FileSystem.Statistics)8 Test (org.junit.Test)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)2 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)1