use of org.apache.cassandra.metrics.CacheMetrics in project cassandra by apache.
the class KeyCacheCqlTest method test2iKeyCachePathsSaveKeysForDroppedTable.
private void test2iKeyCachePathsSaveKeysForDroppedTable() throws Throwable {
String table = createTable("CREATE TABLE %s (" + commonColumnsDef + "PRIMARY KEY ((part_key_a, part_key_b),clust_key_a,clust_key_b,clust_key_c))");
createIndex("CREATE INDEX some_index ON %s (col_int)");
insertData(table, "some_index", true);
clearCache();
CacheMetrics metrics = CacheService.instance.keyCache.getMetrics();
for (int i = 0; i < 10; i++) {
UntypedResultSet result = execute("SELECT part_key_a FROM %s WHERE col_int = ?", i);
assertEquals(500, result.size());
}
long hits = metrics.hits.getCount();
long requests = metrics.requests.getCount();
assertEquals(0, hits);
assertEquals(210, requests);
for (int i = 0; i < 10; i++) {
UntypedResultSet result = execute("SELECT part_key_a FROM %s WHERE col_int = ?", i);
// 100 part-keys * 50 clust-keys
// indexed on part-key % 10 = 10 index partitions
// (50 clust-keys * 100-part-keys / 10 possible index-values) = 500
assertEquals(500, result.size());
}
metrics = CacheService.instance.keyCache.getMetrics();
hits = metrics.hits.getCount();
requests = metrics.requests.getCount();
assertEquals(200, hits);
assertEquals(420, requests);
dropTable("DROP TABLE %s");
CacheService.instance.keyCache.submitWrite(Integer.MAX_VALUE).get();
CacheService.instance.keyCache.clear();
Assert.assertEquals(0, CacheService.instance.keyCache.size());
// then load saved
CacheService.instance.keyCache.loadSaved();
Iterator<KeyCacheKey> iter = CacheService.instance.keyCache.keyIterator();
while (iter.hasNext()) {
KeyCacheKey key = iter.next();
TableMetadataRef tableMetadataRef = Schema.instance.getTableMetadataRef(key.tableId);
Assert.assertFalse(tableMetadataRef.keyspace.equals("KEYSPACE_PER_TEST"));
Assert.assertFalse(tableMetadataRef.name.startsWith(table));
}
}
use of org.apache.cassandra.metrics.CacheMetrics in project cassandra by apache.
the class KeyCacheCqlTest method testKeyCacheClustered.
private void testKeyCacheClustered() throws Throwable {
String table = createTable("CREATE TABLE %s (" + commonColumnsDef + "PRIMARY KEY ((part_key_a, part_key_b),clust_key_a,clust_key_b,clust_key_c))");
insertData(table, null, true);
clearCache();
// 10 queries, each 50 result rows
for (int i = 0; i < 10; i++) {
assertEquals(50, execute("SELECT col_text FROM %s WHERE part_key_a = ? AND part_key_b = ?", i, Integer.toOctalString(i)).size());
}
CacheMetrics metrics = CacheService.instance.keyCache.getMetrics();
long hits = metrics.hits.getCount();
long requests = metrics.requests.getCount();
assertEquals(0, hits);
assertEquals(10, requests);
// 10 queries, each 50 result rows
for (int i = 0; i < 10; i++) {
assertEquals(50, execute("SELECT col_text FROM %s WHERE part_key_a = ? AND part_key_b = ?", i, Integer.toOctalString(i)).size());
}
metrics = CacheService.instance.keyCache.getMetrics();
hits = metrics.hits.getCount();
requests = metrics.requests.getCount();
assertEquals(10, hits);
assertEquals(10 + 10, requests);
// 100 queries - must get a hit in key-cache
for (int i = 0; i < 10; i++) {
for (int c = 0; c < 10; c++) {
assertRows(execute("SELECT col_text, col_long FROM %s WHERE part_key_a = ? AND part_key_b = ? and clust_key_a = ?", i, Integer.toOctalString(i), c), new Object[] { String.valueOf(i) + '-' + String.valueOf(c), (long) c });
}
}
metrics = CacheService.instance.keyCache.getMetrics();
hits = metrics.hits.getCount();
requests = metrics.requests.getCount();
assertEquals(10 + 100, hits);
assertEquals(20 + 100, requests);
// 5000 queries - first 10 partitions already in key cache
for (int i = 0; i < 100; i++) {
for (int c = 0; c < 50; c++) {
assertRows(execute("SELECT col_text, col_long FROM %s WHERE part_key_a = ? AND part_key_b = ? and clust_key_a = ?", i, Integer.toOctalString(i), c), new Object[] { String.valueOf(i) + '-' + String.valueOf(c), (long) c });
}
}
hits = metrics.hits.getCount();
requests = metrics.requests.getCount();
assertEquals(110 + 4910, hits);
assertEquals(120 + 5500, requests);
}
use of org.apache.cassandra.metrics.CacheMetrics in project cassandra by apache.
the class LargePartitionsTest method keyCacheMetrics.
private static void keyCacheMetrics(String title) {
CacheMetrics metrics = CacheService.instance.keyCache.getMetrics();
System.out.println("Key cache metrics " + title + ": capacity:" + metrics.capacity.getValue() + " size:" + metrics.size.getValue() + " entries:" + metrics.entries.getValue() + " hit-rate:" + metrics.hitRate.getValue() + " one-min-rate:" + metrics.oneMinuteHitRate.getValue());
}
use of org.apache.cassandra.metrics.CacheMetrics in project cassandra by apache.
the class InstrumentingCache method clear.
public void clear() {
map.clear();
metrics = new CacheMetrics(type, map);
}
use of org.apache.cassandra.metrics.CacheMetrics in project cassandra by apache.
the class KeyCacheCqlTest method clearCache.
private static void clearCache() {
CassandraMetricsRegistry.Metrics.getNames().forEach(CassandraMetricsRegistry.Metrics::remove);
CacheService.instance.keyCache.clear();
CacheMetrics metrics = CacheService.instance.keyCache.getMetrics();
Assert.assertEquals(0, metrics.entries.getValue().intValue());
Assert.assertEquals(0L, metrics.hits.getCount());
Assert.assertEquals(0L, metrics.requests.getCount());
Assert.assertEquals(0L, metrics.size.getValue().longValue());
}
Aggregations