All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cacheOverflow.README.html Maven / Gradle / Ivy





  
  
  

vFabric GemFire®

cacheOverflow

Java Caching API Programming Example


The cacheOverflow example program demonstrates the "overflow" feature of GemFire cache regions. The example is located in the GemFire installation under examples/dist/cacheOverflow.

Before running this application, you need to start a terminal session and configure its environment according to the instructions provided under the GemFire installation in examples/EnvSetup.html.

After the environment has been set, change directory to examples/dist/cacheOverflow in the SampleCode distribution directory.

You can run the cacheOverflow example with no command line arguments to obtain usage information.


usage: java cacheOverflow.CacheOverflow [options] args

Where [options] are
  -synchronous       Writes to disk are synchronous
  -backup            Backup the region data on disk (data will be written
                     to disk as soon as it is added to the region). Restarting
                     the VM with the -backup flag will recover it's contents.
  -validate          Instead of populating a region validates its contents.
  -disableCompaction Save the old backup files instead of compacting them

Where args are
  threads            Number of threads adding to region
  arrays             Number of 8 kilobyte arrays added by each thread
  overflowThreshold  Number of megabytes of region data that can reside
                     in the VM before overflowing to disk
  maxOplogSize       Number of megabytes of region data that can be written
                     to a backup file before rolling over to a new file
  dir+               One or more directories in which to write region data

The cacheOverflow example launches one or more threads that populate a GemFire region with 8 kilobyte chunks of data (long arrays of size 1024). Once the amount of region data exceeds the specified threshold, the data is overflowed to disk, thus allowing the logical size of the region to exceed the amount of heap space in the VM.

Enter the following command exactly as shown. The call puts a total of 20*100*8K = 16MB of data into a region with a size limit of 1 megabyte, so 15 megabytes are overflowed (into a 30 megabyte file in the current working directory) as the threads run.

    java cacheOverflow.CacheOverflow 20 100 1 30 .

When the threads finish, the program exits. This forces a cache close and region destruction.

If you run the same command with the -backup flag, it will store all of the entries on disk. It will still keep 1 megabyte in the in memory cache.

    java cacheOverflow.CacheOverflow -backup 20 100 1 30 .

Running the program with the -backup flag again will recover the region contents from disk. Run it with both the -backup and -verify flags to make sure the data was recovered.

    java cacheOverflow.CacheOverflow -backup -validate 20 100 1 30 .

While the program itself does not have very interesting output, there are a number of GemFire statistics that are worth observing. The example program creates it's own statistics in WorkerStats.java. It keeps track of the number of bytes it has added to the cache (the bytesAdded statistic of the WorkerStats). GemFire itself tracks a several of stats related to cache operations. You can see the number of region entry values that have been overflowed to disk (the lruEvictions statistic of MemLRUStatistics, and the amount of time that is spent writing data to disk (the writeTime statistic of DiskRegionStatistics).

The program's statistics are archived in a file named statArchive.gfs. The optional VSD tool can be used to view these statistics (available through the vFabric GemFire Product Page). Run this command to the view the statistics:

  vsd statArchive.gfs

By default, the cacheOverflow program runs as a standalone GemFire application, meaning it does not join a distributed system, but only creates a cache. The CacheOverflow program can be configured to join a distributed system by setting certain distribution-related system properties as outlined in the online documentation for the DistributedSystem class and in the GemFire User's Guide.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy