usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [08/20] incubator-usergrid git commit: Added timer for cpEntityManager and CpRelationManager to cover commands made by entity managers.
Date Sat, 07 Mar 2015 01:05:35 GMT
Added timer for cpEntityManager and CpRelationManager to cover commands made by entity managers.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/d3b469ea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/d3b469ea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/d3b469ea

Branch: refs/heads/USERGRID-416
Commit: d3b469eae7047c1cca20ed7c18727ba78f2618b6
Parents: b3d4eb2
Author: GERey <greyes@apigee.com>
Authored: Thu Mar 5 11:28:05 2015 -0800
Committer: GERey <greyes@apigee.com>
Committed: Thu Mar 5 11:28:05 2015 -0800

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 62 +++++++++++++++++++-
 .../corepersistence/CpRelationManager.java      | 25 +++++++-
 .../cassandra/CassandraPersistenceUtils.java    |  2 +-
 3 files changed, 82 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b469ea/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 10e7926..4355638 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -309,6 +309,7 @@ public class CpEntityManager implements EntityManager {
 
         Entity entity = batchCreate( m, entityType, null, properties, importId, timestampUuid
);
 
+        //Adding graphite metrics
         Timer.Context timeCassCreation = corePersistanceTimer.time();
         m.execute();
         timeCassCreation.stop();
@@ -342,7 +343,10 @@ public class CpEntityManager implements EntityManager {
 
         A entity = batchCreate( m, entityType, entityClass, properties, importId, timestampUuid
);
 
+        //Adding graphite metrics
+        Timer.Context timeEntityCassCreation = corePersistanceTimer.time();
         m.execute();
+        timeEntityCassCreation.stop();
 
         return entity;
     }
@@ -989,8 +993,10 @@ public class CpEntityManager implements EntityManager {
                 cpEntity.getId().getType(), cpEntity.getId().getUuid(), cpEntity.getVersion()
         } );
 
-
+        //Adding graphite metrics
+        Timer.Context timeESBatch = corePersistanceTimer.time();
         BetterFuture future = ei.createBatch().index( defaultIndexScope, cpEntity ).execute();
+        timeESBatch.stop();
         // update in all containing collections and connection indexes
         CpRelationManager rm = ( CpRelationManager ) getRelationManager( entityRef );
         rm.updateContainingCollectionAndCollectionIndexes( cpEntity );
@@ -1027,7 +1033,10 @@ public class CpEntityManager implements EntityManager {
 
         batch = batchUpdateDictionary( batch, entity, dictionaryName, elementName, elementValue,
false, timestampUuid );
 
+        //Adding graphite metrics
+        Timer.Context timeDictionaryCreation = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeDictionaryCreation.stop();
     }
 
 
@@ -1048,7 +1057,10 @@ public class CpEntityManager implements EntityManager {
             batch = batchUpdateDictionary( batch, entity, dictionaryName, elementValue, null,
false, timestampUuid );
         }
 
+        //Adding graphite metrics
+        Timer.Context timeAddingSetDictionary = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeAddingSetDictionary.stop();
     }
 
 
@@ -1070,7 +1082,10 @@ public class CpEntityManager implements EntityManager {
                     elementValue.getValue(), false, timestampUuid );
         }
 
+        //Adding graphite metrics
+        Timer.Context timeMapDictionary = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeMapDictionary.stop();
     }
 
 
@@ -1247,8 +1262,11 @@ public class CpEntityManager implements EntityManager {
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId
), be );
 
         batch = batchUpdateDictionary( batch, entity, dictionaryName, elementName, true,
timestampUuid );
-
+        //Adding graphite metrics
+        Timer.Context timeRemoveDictionary = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeRemoveDictionary.stop();
+
     }
 
 
@@ -1583,8 +1601,10 @@ public class CpEntityManager implements EntityManager {
         CassandraPersistenceUtils.addInsertToMutator( batch, ENTITY_DICTIONARIES,
                 CassandraPersistenceUtils.key( ownerId, DICTIONARY_SETS ), Schema.DICTIONARY_ROLENAMES,
null,
                 timestamp );
-
+        //Adding graphite metrics
+        Timer.Context timeCreateBatchRole= corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeCreateBatchRole.stop();
 
         return get( id, Role.class );
     }
@@ -1598,7 +1618,10 @@ public class CpEntityManager implements EntityManager {
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId
), be );
         CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
             getRolePermissionsKey( roleName ), permission, ByteBuffer.allocate( 0 ), timestamp
);
+        //Adding graphite metrics
+        Timer.Context timeGrantRolePermission = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeGrantRolePermission.stop();
     }
 
 
@@ -1613,7 +1636,11 @@ public class CpEntityManager implements EntityManager {
             CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
                 getRolePermissionsKey( roleName ), permission, ByteBuffer.allocate( 0 ),
timestamp);
         }
+        //Adding graphite metrics
+        Timer.Context timeGrantRolePermissions = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeGrantRolePermissions.stop();
+
     }
 
 
@@ -1643,7 +1670,10 @@ public class CpEntityManager implements EntityManager {
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId
), be);
         CassandraPersistenceUtils.addDeleteToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
                 getRolePermissionsKey( roleName ), permission, timestamp );
+        //Adding graphite metrics
+        Timer.Context timeRevokeRolePermission = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeRevokeRolePermission.stop();
     }
 
 
@@ -1707,7 +1737,11 @@ public class CpEntityManager implements EntityManager {
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId
), be );
         CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
             getRolePermissionsKey( groupId, roleName ), permission, ByteBuffer.allocate(
0 ), timestamp );
+
+        //Adding graphite metrics
+        Timer.Context timeGroupRolePermission = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeGroupRolePermission.stop();
     }
 
 
@@ -1719,7 +1753,10 @@ public class CpEntityManager implements EntityManager {
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId
), be );
         CassandraPersistenceUtils.addDeleteToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
                 getRolePermissionsKey( groupId, roleName ), permission, timestamp );
+        //Adding graphite metrics
+        Timer.Context timeRevokeGroupRolePermission = corePersistanceTimer.time();
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
+        timeRevokeGroupRolePermission.stop();
     }
 
 
@@ -1868,7 +1905,10 @@ public class CpEntityManager implements EntityManager {
             counterUtils.batchIncrementAggregateCounters( m, applicationId, userId, groupId,
null,
                     category, counterName, value, cassandraTimestamp / 1000, cassandraTimestamp
);
 
+            //Adding graphite metrics
+            Timer.Context timeIncrementAggregateCounters = corePersistanceTimer.time();
             CassandraPersistenceUtils.batchExecute( m, CassandraService.RETRY_COUNT );
+            timeIncrementAggregateCounters.stop();
         }
     }
 
@@ -1893,9 +1933,12 @@ public class CpEntityManager implements EntityManager {
         q.setColumnFamily( APPLICATION_AGGREGATE_COUNTERS.toString() );
         q.setRange( start, finish, false, ALL_COUNT );
 
+        //Adding graphite metrics
+        Timer.Context timeGetAggregateCounters = corePersistanceTimer.time();
         QueryResult<CounterSlice<Long>> r = q.setKey(
                 counterUtils.getAggregateCounterRow( counterName, userId, groupId, queueId,
category, resolution ) )
                                              .execute();
+        timeGetAggregateCounters.stop();
 
         List<AggregateCounter> counters = new ArrayList<AggregateCounter>();
         for ( HCounterColumn<Long> column : r.get().getColumns() ) {
@@ -1965,7 +2008,11 @@ public class CpEntityManager implements EntityManager {
         MultigetSliceCounterQuery<String, Long> q = HFactory.createMultigetSliceCounterQuery(
ko, se, le );
         q.setColumnFamily( APPLICATION_AGGREGATE_COUNTERS.toString() );
         q.setRange( start, finish, false, ALL_COUNT );
+        //Adding graphite metrics
+        Timer.Context timeGetAggregateCounters = corePersistanceTimer.time();
         QueryResult<CounterRows<String, Long>> rows = q.setKeys( selections.keySet()
).execute();
+        timeGetAggregateCounters.stop();
+
 
         List<AggregateCounterSet> countSets = new ArrayList<AggregateCounterSet>();
         for ( CounterRow<String, Long> r : rows.get() ) {
@@ -2088,7 +2135,10 @@ public class CpEntityManager implements EntityManager {
         SliceCounterQuery<UUID, String> q = createCounterSliceQuery( ko, ue, se );
         q.setColumnFamily( ENTITY_COUNTERS.toString() );
         q.setRange( null, null, false, ALL_COUNT );
+        //Adding graphite metrics
+        Timer.Context timeEntityCounters = corePersistanceTimer.time();
         QueryResult<CounterSlice<String>> r = q.setKey( entityId ).execute();
+        timeEntityCounters.stop();
         for ( HCounterColumn<String> column : r.get().getColumns() ) {
             counters.put( column.getName(), column.getValue() );
         }
@@ -2112,7 +2162,10 @@ public class CpEntityManager implements EntityManager {
             counterUtils.batchIncrementAggregateCounters(
                     m, applicationId, userId, groupId, null, category, counters, timestamp
);
 
+            //Adding graphite metrics
+            Timer.Context timeIncrementCounters = corePersistanceTimer.time();
             CassandraPersistenceUtils.batchExecute( m, CassandraService.RETRY_COUNT );
+            timeIncrementCounters.stop();
         }
     }
 
@@ -2843,7 +2896,10 @@ public class CpEntityManager implements EntityManager {
         //
         //        batch.index(appAllTypesScope, memberEntity);
 
+        //Adding graphite metrics
+        Timer.Context timeIndexEntityCollection = corePersistanceTimer.time();
         batch.execute();
+        timeIndexEntityCollection.stop();
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b469ea/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 302f18d..786b0f5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -61,6 +61,7 @@ import org.apache.usergrid.persistence.cassandra.index.IndexBucketScanner;
 import org.apache.usergrid.persistence.cassandra.index.IndexScanner;
 import org.apache.usergrid.persistence.cassandra.index.NoOpIndexScanner;
 import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.entities.Group;
 import org.apache.usergrid.persistence.entities.User;
@@ -105,6 +106,7 @@ import org.apache.usergrid.utils.IndexUtils;
 import org.apache.usergrid.utils.MapUtils;
 import org.apache.usergrid.utils.UUIDUtils;
 
+import com.codahale.metrics.Timer;
 import com.google.common.base.Preconditions;
 import com.yammer.metrics.annotation.Metered;
 
@@ -188,7 +190,7 @@ public class CpRelationManager implements RelationManager {
 
     private ResultsLoaderFactory resultsLoaderFactory;
 
-
+    private Timer cpRelationTimer;
 
     public CpRelationManager() {}
 
@@ -198,7 +200,8 @@ public class CpRelationManager implements RelationManager {
             CpEntityManagerFactory emf,
             UUID applicationId,
             EntityRef headEntity,
-            IndexBucketLocator indexBucketLocator ) {
+            IndexBucketLocator indexBucketLocator,
+            MetricsFactory metricsFactory) {
 
         Assert.notNull( em, "Entity manager cannot be null" );
         Assert.notNull( emf, "Entity manager factory cannot be null" );
@@ -219,6 +222,8 @@ public class CpRelationManager implements RelationManager {
         this.cass = em.getCass(); // TODO: eliminate need for this via Core Persistence
         this.indexBucketLocator = indexBucketLocator; // TODO: this also
 
+        this.cpRelationTimer = metricsFactory.getTimer( CpRelationManager.class, "relation.manager.timer"
);
+
         // load the Core Persistence version of the head entity as well
         this.headEntityScope = getCollectionScopeNameFromEntityType(
                 applicationScope.getApplication(), headEntity.getType());
@@ -441,8 +446,10 @@ public class CpRelationManager implements RelationManager {
                     }
                 } ).count().toBlocking().lastOrDefault( 0 );
 
-
+        //Adding graphite metrics
+        Timer.Context timeElasticIndexBatch = cpRelationTimer.time();
         entityIndexBatch.execute();
+        timeElasticIndexBatch.stop();
 
         logger.debug( "updateContainingCollectionsAndCollections() updated {} indexes", count
);
     }
@@ -1065,7 +1072,11 @@ public class CpRelationManager implements RelationManager {
         Keyspace ko = cass.getApplicationKeyspace( applicationId );
         Mutator<ByteBuffer> m = createMutator( ko, be );
         batchUpdateEntityConnection( m, false, connection, UUIDGenerator.newTimeUUID() );
+        //Added Graphite Metrics
+        Timer.Context timeElasticIndexBatch = cpRelationTimer.time();
         batchExecute( m, CassandraService.RETRY_COUNT );
+        timeElasticIndexBatch.stop();
+
 
         return connection;
     }
@@ -1236,7 +1247,11 @@ public class CpRelationManager implements RelationManager {
         Mutator<ByteBuffer> m = createMutator( ko, be );
         batchUpdateEntityConnection(
                 m, true, ( ConnectionRefImpl ) connectionRef, UUIDGenerator.newTimeUUID()
);
+
+        //Added Graphite Metrics
+        Timer.Context timeDeleteConnections = cpRelationTimer.time();
         batchExecute( m, CassandraService.RETRY_COUNT );
+        timeDeleteConnections.stop();
 
         EntityRef connectingEntityRef = connectionRef.getConnectingEntity();  // source
         EntityRef connectedEntityRef = connectionRef.getConnectedEntity();  // target
@@ -1291,7 +1306,11 @@ public class CpRelationManager implements RelationManager {
 //
 //        batch.deindex( allTypesIndexScope, targetEntity );
 
+        //Added Graphite Metrics
+        Timer.Context timeDeleteConnection = cpRelationTimer.time();
         batch.execute();
+        timeDeleteConnection.stop();
+
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d3b469ea/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraPersistenceUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraPersistenceUtils.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraPersistenceUtils.java
index 45c9784..174e0a4 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraPersistenceUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraPersistenceUtils.java
@@ -327,7 +327,7 @@ public class CassandraPersistenceUtils {
         return batch;
     }
 
-
+    //No longer does retries
     public static MutationResult batchExecute( Mutator<?> m, int retries ) {
         return m.execute();
 


Mime
View raw message