Skip to content

Instantly share code, notes, and snippets.

@beltran
Created March 8, 2017 20:23
Show Gist options
  • Save beltran/a947c1f8271b5d4000608a0d01051834 to your computer and use it in GitHub Desktop.
Save beltran/a947c1f8271b5d4000608a0d01051834 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import uuid
import time
import dse
from dse import cluster as cassandra_cluster
#from dse.io.geventreactor import GeventConnection
from dse.io.eventletreactor import EventletConnection
from dse.io.libevreactor import LibevConnection
from dse.io.asyncorereactor import AsyncoreConnection
from dse.concurrent import execute_concurrent
import concurrent
import os
import resource
from itertools import cycle
import logging
log = logging.getLogger()
log.setLevel('ERROR')
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
log.addHandler(handler)
connection_class=EventletConnection
import code
import signal
if connection_class == EventletConnection:
from eventlet import monkey_patch
monkey_patch()
signal.signal(signal.SIGUSR2, lambda sig, frame: code.interact())
local_pid = os.getpid()
#cluster = cassandra_cluster.Cluster(("127.0.0.1", "127.0.0.2", "127.0.0.3",), connection_class=LibevConnection)
cluster = cassandra_cluster.Cluster(("127.0.0.1", "127.0.0.2", "127.0.0.3"), connection_class=connection_class)
session = cluster.connect()
session.execute('''
CREATE KEYSPACE IF NOT EXISTS test3rf
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}''')
session.execute('''
CREATE TABLE IF NOT EXISTS test3rf.test (
k int PRIMARY KEY,
v int )''')
def concurrent_f():
statements = cycle(("INSERT INTO test3rf.test (k, v) VALUES (%s, %s)",))
parameters = [(i, i) for i in range(1000)]
execute_concurrent(session, list(zip(statements, parameters)), raise_on_first_error = True)
count = 0
print("Starting iterations")
while 1:
try:
concurrent_f()
except:
pass
time.sleep(0.0001)
count = count + 1
if not count % 1:
print(resource.getrusage(resource.RUSAGE_SELF))
print("The end")
from tests.integration import use_cluster, get_node, use_singledc
import time
from random import randint
import sys
import os
def kill_cassandra_abruptly():
print("Abruptly stopping cassandra and everything with the name of cassandra")
os.system("ps aux | grep cassandra | awk '{print $2}' | xargs kill -9")
use_singledc()
print("\n\nLaunch poc_hangs now")
count= 0
while 1:
time.sleep(20)
print("Stopping node")
kill_cassandra_abruptly()
time.sleep(10)
print("Launching cassandra again")
use_singledc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment