Esempio n. 1
0
class Stress(object):
    opcounts = array('i', [0] * n_threads)
    latencies = array('d', [0] * n_threads)
    keycounts = array('i', [0] * n_threads)

    def create_threads(self,type):
        threads = []
        for i in xrange(n_threads):
            th = OperationFactory.create(type, i, self.opcounts, self.keycounts, self.latencies)
            threads.append(th)
            th.start()
        return threads

    def run_test(self,filename,threads):
        start_t = time.time()
        if filename:
            outf = open(filename,'w')
        else:
            outf = sys.stdout
        outf.write('total,interval_op_rate,interval_key_rate,avg_latency,elapsed_time\n')
        epoch = total = old_total = latency = keycount = old_keycount = old_latency = 0
        epoch_intervals = (options.interval * 10) # 1 epoch = 1 tenth of a second
        terminate = False
        while not terminate:
            time.sleep(0.1)
            if not [th for th in threads if th.isAlive()]:
                terminate = True
            epoch = epoch + 1
            if terminate or epoch > epoch_intervals:
                epoch = 0
                old_total, old_latency, old_keycount = total, latency, keycount
                total = sum(self.opcounts[th.idx] for th in threads)
                latency = sum(self.latencies[th.idx] for th in threads)
                keycount = sum(self.keycounts[th.idx] for th in threads)
                opdelta = total - old_total
                keydelta = keycount - old_keycount
                delta_latency = latency - old_latency
                if opdelta > 0:
                    delta_formatted = (delta_latency / opdelta)
                else:
                    delta_formatted = 'NaN'
                elapsed_t = int(time.time() - start_t)
                outf.write('%d,%d,%d,%s,%d\n' 
                           % (total, opdelta / options.interval, keydelta / options.interval, delta_formatted, elapsed_t))

    def insert(self):
        threads = self.create_threads('insert')
        self.run_test(options.file,threads);

    def read(self):
        threads = self.create_threads('read')
        self.run_test(options.file,threads);
        
    def rangeslice(self):
        threads = self.create_threads('rangeslice')
        self.run_test(options.file,threads);
Esempio n. 2
0
class Stress(object):
    counts = array('i', [0] * n_threads)
    latencies = array('d', [0] * n_threads)

    def create_threads(self, type):
        threads = []
        for i in xrange(n_threads):
            th = OperationFactory.create(type, i, self.counts, self.latencies)
            threads.append(th)
            th.start()
        return threads

    def run_test(self, filename, threads):
        start_t = time.time()
        if filename:
            outf = open(filename, 'w')
        else:
            outf = sys.stdout
        outf.write('total,interval_op_rate,avg_latency,elapsed_time\n')
        total = old_total = latency = old_latency = 0
        while True:
            time.sleep(options.interval)
            old_total, old_latency = total, latency
            total = sum(self.counts[th.idx] for th in threads)
            latency = sum(self.latencies[th.idx] for th in threads)
            delta = total - old_total
            delta_latency = latency - old_latency
            delta_formatted = (delta_latency / delta) if delta > 0 else 'NAN'
            elapsed_t = int(time.time() - start_t)
            outf.write(
                '%d,%d,%s,%d\n' %
                (total, delta / options.interval, delta_formatted, elapsed_t))
            if not [th for th in threads if th.isAlive()]:
                break

    def insert(self):
        threads = self.create_threads('insert')
        self.run_test(options.file, threads)

    def read(self):
        threads = self.create_threads('read')
        self.run_test(options.file, threads)

    def rangeslice(self):
        threads = self.create_threads('rangeslice')
        self.run_test(options.file, threads)
Esempio n. 3
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# expects a Cassandra server to be running and listening on port 9160.
# (read tests expect insert tests to have run first too.)

from __future__ import with_statement

have_multiproc = False
try:
    from multiprocessing import Array as array, Process as Thread
    from uuid import uuid1 as get_ident
    array('i', 1) # catch "This platform lacks a functioning sem_open implementation"
    Thread.isAlive = Thread.is_alive
    have_multiproc = True
except ImportError:
    from threading import Thread
    from thread import get_ident
    from array import array
from hashlib import md5
import time, random, sys, os
from random import randint, gauss
from optparse import OptionParser

from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol
Esempio n. 4
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# expects a Cassandra server to be running and listening on port 9160.
# (read tests expect insert tests to have run first too.)

from __future__ import with_statement

have_multiproc = False
try:
    from multiprocessing import Array as array, Process as Thread
    from uuid import uuid1 as get_ident
    array(
        'i',
        1)  # catch "This platform lacks a functioning sem_open implementation"
    Thread.isAlive = Thread.is_alive
    have_multiproc = True
except ImportError:
    from threading import Thread
    from thread import get_ident
    from array import array
from hashlib import md5
import time, random, sys, os
from random import randint, gauss
from optparse import OptionParser

from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient