Last active
October 6, 2015 10:10
-
-
Save mlowicki/e3d44775ed9ebfc3a21e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from time import sleep | |
| from cassandra import ConsistencyLevel | |
| from cassandra.policies import ( | |
| DCAwareRoundRobinPolicy, | |
| FallthroughRetryPolicy, | |
| TokenAwarePolicy | |
| ) | |
| from cassandra.cqlengine.connection import setup, execute | |
| hosts = [ | |
| '10.210.3.221', # db1 | |
| '10.210.3.224', # db2 | |
| '10.210.3.230', # db3 | |
| '10.210.3.160', # db4 | |
| '10.210.3.161', # db5 | |
| '10.210.3.162', # db6 | |
| '10.210.3.117' # db7 | |
| ] | |
| setup( | |
| hosts, | |
| 'sync', | |
| retry_connect=True, | |
| lazy_connect=False, | |
| load_balancing_policy=TokenAwarePolicy(DCAwareRoundRobinPolicy('Amsterdam')), | |
| #consistency=ConsistencyLevel.LOCAL_QUORUM, | |
| consistency=ConsistencyLevel.ALL, | |
| default_retry_policy=FallthroughRetryPolicy()) | |
| from cassandra.cqlengine.connection import session | |
| iden = 's1' | |
| user_id = 'consistency_stress_tester' | |
| data_type_id = 666 | |
| for i in range(10): | |
| print 'loop #', i | |
| res = execute( | |
| """ | |
| SELECT * FROM sync.entity_by_id2 WHERE user_id=%s AND data_type_id=%s | |
| """, | |
| (user_id, data_type_id), | |
| consistency_level=ConsistencyLevel.ALL | |
| ) | |
| if len(res) > 0: | |
| print 'old entity_by_id.version', res[0]['version'] | |
| execute( | |
| """ | |
| INSERT INTO sync.entity_by_id2 (user_id, data_type_id, version, id) VALUES (%s, %s, %s, %s) | |
| """, | |
| (user_id, data_type_id, i, iden), | |
| consistency_level=ConsistencyLevel.ALL | |
| ) | |
| sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment