Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/repository datastax migration performance #146

Conversation

bargenilesh
Copy link
Contributor

Batch assignment flow optimizations...

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 73.62% when pulling 3c03059 on feature/repository-datastax-migration-performance into 169002b on feature/repository-datastax-migration.

Table<Experiment.ID, Experiment.Label, Experiment> allExperiments = repository.getExperimentList(applicationName);
long sTime,totalSTime;
totalSTime=System.currentTimeMillis();
sTime=System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this line to above line like long sTime=System.currentTimeMillis(), totalSTime=System.currentTimeMillis();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of sTime and totalSTime as I have removed performance logger...


List<Map> allAssignments = new ArrayList<>();
//allowAssignments is NULL when called from AssignmentsResource.getBatchAssignments()
Set<Experiment.ID> experimentIds = allowAssignments==null?null:allowAssignments.keySet();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return remove null from the code as much as possible, either chagne allowAssignments to Optional or use other syntax like isNull(allowAssignments) ? Set.EMPTY() : allowAssignments.keySet();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed allowAssignments to Optional and then related changes...


List<Map> allAssignments = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LInkedList instead of ArrayList for dynamic sized List

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to LinkedList..

// iterate over all experiments in the application in priority order
for (PrioritizedExperiment experiment : appPriorities.getPrioritizedExperiments()) {
if(LOGGER.isDebugEnabled()) LOGGER.debug("Now processing: {}", experiment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really need isDebugEnabled since the debug message is not expensive operations at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this as having isDebugEnabled avoids a string concatenation in the case if logging LEVEL is not debug...

@@ -458,12 +503,11 @@ public Assignment getAssignment(User.ID userID, Application.Name applicationName
.build();

try {
Assignment assignment = getAssignment(userID, applicationName, label,
Assignment assignment = getAssignment(userID, applicationName, label,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove allowAssingments != null from code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this was existing code, changed to use Optional implementation...

if(logger.isDebugEnabled()) logger.debug("experimentMap=> {}", experimentMap);

int priorityValue=1;
for (com.intuit.wasabi.repository.cassandra.pojo.Application priority : UninterruptibleUtil.getUninterruptibly(applicationFuture).all()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already an getUninterruptibly function from guava, since there isn't much we can do with the exception it is better just log it and move on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to the above comments...

UninterruptibleUtil.getUninterruptibly(userAssignmentsFuture).all().stream().forEach((ExperimentUserByUserIdContextAppNameExperimentId uaPojo) -> {
Experiment.ID experimentID = Experiment.ID.valueOf(uaPojo.getExperimentId());
Experiment exp = experimentMap.get(experimentID);
if(exp!=null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNotNull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done...


//experimentIds is NULL means experimentBatch.labels are present.
//Use experimentBatch.labels to populate experimentIds
if(experimentIds==null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to Optional implementation as part of one of the previous comment..

Set<Experiment.Label> expLabels = new HashSet<>();
for(Experiment.ID expId:experimentIds) {
Experiment exp = experimentMap.get(expId);
if(exp!=null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNotNull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already taken care from one of the previous comment...

Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString());
resultList = StreamSupport.stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false);
} catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) {
throw new RepositoryException("Could not retrieve the experiments for applicationName:\"" + applicationName + "\", page:\"" + pageName, e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not do string concat here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use StringBuilder... Note: This implementation was done similar to the other methods in the same class and so copied and then modified and so other methods are still doing string concatenation...

@@ -611,4 +611,4 @@
</downloadUrls>
</dependency>
</dependencies>
</attributionReport>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file changed automatically by build... What change do you suggest to do here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we just check out the file and the difference will be deleted. But it is just a minor issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok... got it.

@@ -45,6 +46,9 @@
@Query("select * from bucket where experiment_id = ?")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the sync method ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep this method as it is still being used in other places other than batch-assignment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my suggestion - can we use asnyc everywhere ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we could and should bit in this feature I am trying to keep scope limited to Batch assignment only...

@@ -37,6 +38,9 @@
@Query("select * from exclusion where base = ?")
Result<Exclusion> getExclusions(UUID base);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the sync method since we are using async one ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep this method as it is still being used in other places other than batch-assignment.

@@ -40,6 +41,10 @@
@Query("select * from experiment_user_index where user_id = ? and app_name = ? and context = ?")
Result<ExperimentUserByUserIdContextAppNameExperimentId> selectBy(String userId, String appName, String context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - remove sync method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep this method as it is still being used in other places other than batch-assignment

@@ -40,7 +40,7 @@
"values(?,?,?,?)")
Statement insertBy(String appName, String page, UUID experimentId, boolean assign);

/**
/**experi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected typo...

import com.intuit.wasabi.repository.cassandra.pojo.index.UserAssignmentByUserId;
import com.netflix.astyanax.Execution;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need astyanax dependency here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need this dependency... removed...

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 73.62% when pulling fffdf08 on feature/repository-datastax-migration-performance into 169002b on feature/repository-datastax-migration.

@bargenilesh
Copy link
Contributor Author

Thanks @felixgao and @mans4singh for reviewing the code... I have addressed comments, kindly let me know if you have any further comments...

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 73.62% when pulling e36d662 on feature/repository-datastax-migration-performance into 169002b on feature/repository-datastax-migration.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 73.62% when pulling e36d662 on feature/repository-datastax-migration-performance into 169002b on feature/repository-datastax-migration.

@bargenilesh bargenilesh merged commit 5d848a6 into feature/repository-datastax-migration Jan 10, 2017
bargenilesh added a commit that referenced this pull request Jan 11, 2017
* Added initial impl of user feedback repo

* updated comments

* Added unit test for accessor

* Impl + tests for user feedback repo

* Updated test cases

* pojo changes to use lombok

* Audit log repository initial commit

* Corrected bug and skip time since is checked during insert time

* Updated test to create valid app name

* Code cleanup and minor refactoring

* Updated comments

* Added integration tests

* Set parsing log error to warn while retrieving data

* Unit test for audit log repo

* documentation + minor code correction

* Documented issues

* Updated logging

* Initial impl for priorities repo

* initial checkin for CassandraAuthorizationRepository and test

* removed unused imports

* add application list accessor and refactor cassandra authorization repsitory to use ApplicaitonList instead of plain String object

* remove todo

* refactor name app_name to appName

* add binding to cassandra repository from interface

* fix the badly refactored appName and add the missing UserDirectory module

* fix the appName one more time

* Added repo and unit/integration tests

* add logging to log the keyspace it is using

* Corrected column name

* fix app_name refactor

* Corrected comments

* Added feedback repository intergration test

* Updated comment

* Updated comments

* fix the application name cannot be * problem

* First cut of mutex repo/accessor + integration tests

* Added integration tests

* Corrected test cases to take cassandra as argument

* fix unit test fail

* add integration test and more accessors. also fixed the local maven causes problem

* refactor the naming and location of the sources

* add more method to accessor

* added page experiment index accessor

* Added default and missing label

* Corrected query and added simple integration test

* Changed UserBucketIndexAccessor interface insert/delete to return void

* add cassandra page repository using datastax.  modified the original PageExperiment.java to include additional method in the builder

* added additional accessor providers and fix cross import error and added page repository data provider for integration test

* fix bad query in accessor and add additional test cases in repository module test

* ExperimentAccessor + integration test for insert/get only

* changed parameters to use proper java camel casing

* add page respository integration test

* Added methods and test cases for experiment and bucket accessors

* Added method to get experiments

* import list

* Mutex repo updates + integration + unit tests

* Updated comments and added tests

* rename mutexaccssor to exclusionaccessor and add the mapping to guice module

* add provider for all the accessors and remove some of the cross module dependencies mapping

* Added integration tests for priorities repository

* package base reordering

* fix compile problem

* Updated pom for objects dependency

* fix bad import and missing interfaces

* Application list accessor + integration tests

* Integration tests for audit accessor + updates to experiment utils

* Commented out astynax dependency from interface and database impl

* refactor assignmnet builder to be proper builder and remove setters in original object. Also added AssignmentCountEnvelope.java that is missing from original repository

* Added acessor + integration and unit test

* Update notice and added comments

* Updated guice module

* fix bad table name

* add some comment on existing code base and fixed accessor parameter type mismatch

* fix type mismatch

* Experiment repo + few integration tests

* Added integration tests

* added updateStateIndex back and minor documentation updates

* updated get experiment list method

* More integration tests

* add missing methods for insert

* Updated test case

* Added more tests

* removing testng integration test to a different directory

* add missing deleteBy method

* Added integration tests for experiment repo

* initial repo migration for cassandra assignment repo, with incomplete code and unit test

* Added ExperimentRuleCacheUpdateEnvelope

* removed original repository/cassandra module and replaced with the new datastax module. the code compiles fine but have not tested for functional test

* Updated module

* added more unit test and fix some code issue with assignment repository

* rearrange some accessors binding

* fix accessor errors

* Refactored tests

* Corrected assignment-object test

* fix guice error and depdency graph too complicated

* Fixed tests cases

* Corrected some comparisons to exclude description and rule for null vs empty string issue

* Corrected issue with Optional.get() when the Optional is empty

* fix optional get does not consider possible null error

* Add exception handling for create exception - TODO - Validate experiment befor creation

* fix assignment date is null bug

* fix null assignment problem and left some todos for us to revisit soon

* Updated validator and object setters for validation

* Experiment validator test

* Updated mock test cases

* Updated integration and unit tests

* Added unit tests

* Updated test cases

* Http status code cleanup in test

* fix merge conflict issue

* Removed redundant null check

* Removed unused class

* Commented out testng dependencies so that unit test execute

* remove TODO

* fix test case errors

* fix the repository module dependency graph problem

* Corrected mock tests

* Updated test cases

* fix the unit test

* Added more tests cases

* fix merge conflict and new features that are added to develop branch that is not in our feature branch

* add missing mutation script

* fix missing attributes from experiments and rename attribute to sneak case

* Separated unit tests from integration tests

* remove directly dependency of UserToolsModule from Repository module

* add the migration script and reduce the file name for mutation script

* Updated script

* Created integration profile

* Updated build script

* mod: sync [ws]/bin with f/leroy-jenkins for jenkins/wasabi-internal parity

* mod: rm bin stubs

* add shell script and made migration part of the container.sh

* add replication factor to migration script

* added test case for adding to GET all assignments of an Invalid Experiment

* update the migration to be using docker

* set the client's remote host to zero to prefer localdc instead of remote

* fix the local dc token aware policy to be able to connect to direct local dc

* Commented out failing test

* t_AuditLogPaginationSmoke should not use hardcoded username "admin.

* added option to support feature.

* Retrieve individual experiments to maintain priority order

* added the ability to use the migration.sh without docker

* Corrected check for response in case of experiment not found

* Added override properties for database url, username and password

* mod: add [ws]/bin/jenkins.sh

* mod: u/d fpm.sh

* mod: u/d

* mod: u/d repo

* mod: dbug fpm

* mod: dbug fpm

* mod: ui fpm

* mod: rm fpm dbug

* mod: bump release

* Updated autumn version to 1.0.20160714060618.

* refactor cassandra_client_config.properties to remove useless attributes and added more comment on what the new properties should be. Also added the default to pom.xml.

* Feature/datastax-missingcases(getExpByApp,getExpByPage) (#128)

* added test case for invalidapplication added util method in testbase

* added test case for invalidapp and invalidpage

* added test case for invalidapp pages

* corrected the expectedstatus

* Added database system properties to test base

* Feature/table user_assignment_look_up rename and remove user_experiment_index references (#139)

Renaming user assignment lookup and remove references for user experiment index.

* Cleaned up changes for table name change (user assignment look up)

* Updated table name

* Removed commented code

* Added attributions for utils

* Renamed pojo and corrected clustering key

* add the more debugging info for bad rule cache calls

* fix a possible EOF error with keystore

* add more logging info

* fix datastax treat null values as empty string from db causes hyrule to throw exceptions

* make PoolingOptions fully adjustable via configuration file

* Removed lz4 1.1.0 dependency and commented astynax import from bucket class

* add slow query logging and monitoring connection pooling and change logback to use async logger

* Feature/repository datastax migration performance (#146)

* Async Fetch of Experiment Metadata + custom performance logger + Minimize the impact of increase in # of experiments.

* Added comments and logging variable replacements

* Added uninterrupted implementations and unit tests..

* Self review: changed some comments and removed unused code..

* Addressed code review comments...

* Added specific imports and fixed one functional condition...

* Removed system.out from test class...

* Refactored ApiModule so common module installation will not be repeated (#149)

in child class and some modules installation can be overridden.

* Resolved functional test issue and added exception catch and error message while connecting to cassandra...

* 1. Changed version to 1.0.20161107232436-SNAPSHOT
2. Modified 2 props in cassandra_client_config.properties
isSlowQueryLoggingEnabled:False, poolTimeoutMillis:0
3. disabled attribution-maven-plugin
@bargenilesh bargenilesh deleted the feature/repository-datastax-migration-performance branch January 17, 2017 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants