Snippets

Cheyin L Cassandra Session Close Test

Created by Cheyin L last modified

# -*- coding: utf-8 -*-

import os
import uuid

from cassandra import cluster as cassandra_cluster

cluster = cassandra_cluster.Cluster(("u1.local", "u2.local", "u3.local",))

local_pid = os.getpid()

def logstatus(i, msg):
	return # comment out if need status log
	with open("/tmp/logstatus.txt", "w") as fp:
		fp.write(str(i) + msg + "\n")

for i in xrange(1000):
	dbconn = cluster.connect("system")
	logstatus(i, "... connected")
	qresult = dbconn.execute("SELECT now() FROM system.schema_keyspaces")
	for row in qresult:
		pass
	logstatus(i, "... checked")
	qresult = dbconn.execute("SELECT keyspace_name, durable_writes FROM schema_keyspaces")
	for row in qresult:
		pass
	dbconn.shutdown()
	logstatus(i, "... disconnected")
	
	if 0 == (i % 10):
		print "---", i
		os.system("ls /proc/"+str(local_pid)+"/fd")

print "==="
os.system("ls -l /proc/"+str(local_pid)+"/fd")
print "---"
# Test-1 driver version 2.6.0
$ pip freeze
Cython==0.23.4
PyYAML==3.10
blist==1.3.4
bottle==0.12.7
cassandra-driver==2.6.0
futures==3.0.3
pyinotify==0.9.6
scales==1.0.3
six==1.10.0
thrift==0.9.3
web.py==0.37
wsgiref==0.1.2

$ bin/python ~/cassandra_session_fd_close_test.py
--- 0
0  1  2  3
--- 10
0  1  2  3
--- 20
0  1  2  3
--- 30
0  1  2  3
--- 40
0  1  2  3
--- 50
0  1  2  3
--- 60
0  1  2  3
--- 70
0  1  2  3
--- 80
0  1  2  3
--- 90
0  1  2  3
--- 100
0  1  2  3
--- 110
0  1  2  3
--- 120
0  1  2  3
--- 130
0  1  2  3
--- 140
0  1  2  3
--- 150
0  1  2  3
--- 160
0  1  2  3
--- 170
0  1  2  3
--- 180
0  1  2  3
--- 190
0  1  2  3
--- 200
0  1  2  3
--- 210
0  1  2  3
--- 220
0  1  2  3
--- 230
0  1  2  3
--- 240
0  1  2  3
--- 250
0  1  2  3
--- 260
0  1  2  3
--- 270
0  1  2  3
--- 280
0  1  2  3
--- 290
0  1  2  3
--- 300
0  1  2  3
--- 310
0  1  2  3
--- 320
0  1  2  3
--- 330
0  1  2  3
--- 340
0  1  2  3
--- 350
0  1  2  3
--- 360
0  1  2  3
--- 370
0  1  2  3
--- 380
0  1  2  3
--- 390
0  1  2  3
--- 400
0  1  2  3
--- 410
0  1  2  3
--- 420
0  1  2  3
--- 430
0  1  2  3
--- 440
0  1  2  3
--- 450
0  1  2  3
--- 460
0  1  2  3
--- 470
0  1  2  3
--- 480
0  1  2  3
--- 490
0  1  2  3
--- 500
0  1  2  3
--- 510
0  1  2  3
--- 520
0  1  2  3
--- 530
0  1  2  3
--- 540
0  1  2  3
--- 550
0  1  2  3
--- 560
0  1  2  3
--- 570
0  1  2  3
--- 580
0  1  2  3
--- 590
0  1  2  3
--- 600
0  1  2  3
--- 610
0  1  2  3
--- 620
0  1  2  3
--- 630
0  1  2  3
--- 640
0  1  2  3
--- 650
0  1  2  3
--- 660
0  1  2  3
--- 670
0  1  2  3
--- 680
0  1  2  3
--- 690
0  1  2  3
--- 700
0  1  2  3
--- 710
0  1  2  3
--- 720
0  1  2  3
--- 730
0  1  2  3
--- 740
0  1  2  3
--- 750
0  1  2  3
--- 760
0  1  2  3
--- 770
0  1  2  3
--- 780
0  1  2  3
--- 790
0  1  2  3
--- 800
0  1  2  3
--- 810
0  1  2  3
--- 820
0  1  2  3
--- 830
0  1  2  3
--- 840
0  1  2  3
--- 850
0  1  2  3
--- 860
0  1  2  3
--- 870
0  1  2  3
--- 880
0  1  2  3
--- 890
0  1  2  3
--- 900
0  1  2  3
--- 910
0  1  2  3
--- 920
0  1  2  3
--- 930
0  1  2  3
--- 940
0  1  2  3
--- 950
0  1  2  3
--- 960
0  1  2  3
--- 970
0  1  2  3
--- 980
0  1  2  3
--- 990
0  1  2  3
===
total 0
lrwx------ 1 devuser grp01 64 Nov 27 19:00 0 -> /dev/pts/3
lrwx------ 1 devuser grp01 64 Nov 27 19:00 1 -> /dev/pts/3
lrwx------ 1 devuser grp01 64 Nov 27 19:00 2 -> /dev/pts/3
lrwx------ 1 devuser grp01 64 Nov 27 19:00 3 -> socket:[305236109]
---
# Test-2 driver version 3.7.1
$ pip freeze
Cython==0.24.1
PyYAML==3.11
argparse==1.2.1
blist==1.3.6
cassandra-driver==3.7.1
distribute==0.6.24
futures==3.0.5
six==1.10.0
thrift==0.9.3
wsgiref==0.1.2

$ bin/python ~/cassandra_session_fd_close_test.py
--- 0
0  1  2  3  4  5
--- 10
0  1  2  3  4  5
--- 20
0  1  2  3  4  5
--- 30
0  1  2  3  4  5
--- 40
0  1  2  3  4  5
--- 50
0  1  2  3  4  5
--- 60
0  1  2  3  4  5
--- 70
0  1  2  3  4  5
--- 80
0  1  2  3  4  5
--- 90
0  1  2  3  4  5
--- 100
0  1  2  3  4  5
--- 110
0  1  2  3  4  5
--- 120
0  1  2  3  4  5
--- 130
0  1  2  3  4  5
--- 140
0  1  2  3  4  5
--- 150
0  1  2  3  4  5
--- 160
0  1  2  3  4  5
--- 170
0  1  2  3  4  5
--- 180
0  1  2  3  4  5
--- 190
0  1  2  3  4  5
--- 200
0  1  2  3  4  5
--- 210
0  1  2  3  4  5
--- 220
0  1  2  3  4  5
--- 230
0  1  2  3  4  5
--- 240
0  1  2  3  4  5
--- 250
0  1  2  3  4  5
--- 260
0  1  2  3  4  5
--- 270
0  1  2  3  4  5
--- 280
0  1  2  3  4  5
--- 290
0  1  2  3  4  5
--- 300
0  1  2  3  4  5
--- 310
0  1  2  3  4  5
--- 320
0  1  2  3  4  5
--- 330
0  1  2  3  4  5
--- 340
0  1  2  3  4  5
--- 350
0  1  2  3  4  5
--- 360
0  1  2  3  4  5
--- 370
0  1  2  3  4  5
--- 380
0  1  2  3  4  5
--- 390
0  1  2  3  4  5  7
--- 400
0  1  2  3  4  5  6  7	9
--- 410
0  1  2  3  4  5  6  7	9
--- 420
0  1  2  3  4  5  6  7	9
--- 430
0  1  2  3  4  5  6  7	9
--- 440
0  1  2  3  4  5  6  7	9
--- 450
0  1  2  3  4  5  6  7	9
--- 460
0  1  2  3  4  5  6  7	9
--- 470
0  1  2  3  4  5  6  7	9
--- 480
0  1  2  3  4  5  6  7	9
--- 490
0  1  2  3  4  5  6  7	9
--- 500
0  1  2  3  4  5  6  7	9
--- 510
0  1  2  3  4  5  6  7	9
--- 520
0  1  2  3  4  5  6  7	9
--- 530
0  1  2  3  4  5  6  7	9
--- 540
0  1  2  3  4  5  6  7	9
--- 550
0  1  2  3  4  5  6  7	9
--- 560
0  1  2  3  4  5  6  7	9
--- 570
0  1  2  3  4  5  6  7	9
--- 580
0  1  2  3  4  5  6  7	9
--- 590
0  1  2  3  4  5  6  7	9
--- 600
0  1  2  3  4  5  6  7	9
--- 610
0  1  2  3  4  5  6  7	9
--- 620
0  1  2  3  4  5  6  7	9
--- 630
0  1  2  3  4  5  6  7	9
--- 640
0  1  2  3  4  5  6  7	9
--- 650
0  1  2  3  4  5  6  7	9
--- 660
0  1  2  3  4  5  6  7	9
--- 670
0  1  2  3  4  5  6  7	9
--- 680
0  1  2  3  4  5  6  7	9
--- 690
0  1  2  3  4  5  6  7	9
--- 700
0  1  2  3  4  5  6  7	9
--- 710
0  1  2  3  4  5  6  7	9
--- 720
0  1  2  3  4  5  6  7	9
--- 730
0  1  2  3  4  5  6  7	9
--- 740
0  1  2  3  4  5  6  7	9
--- 750
0  1  2  3  4  5  6  7	9
--- 760
0  1  2  3  4  5  6  7	9
--- 770
0  1  2  3  4  5  6  7	9
--- 780
0  1  2  3  4  5  6  7	9
--- 790
0  1  2  3  4  5  6  7	9
--- 800
0  1  2  3  4  5  6  7	9
--- 810
0  1  2  3  4  5  6  7	9
--- 820
0  1  2  3  4  5  6  7	9
--- 830
0  1  2  3  4  5  6  7	9
--- 840
0  1  2  3  4  5  6  7	9
--- 850
0  1  2  3  4  5  6  7	9
--- 860
0  1  2  3  4  5  6  7	9
--- 870
0  1  2  3  4  5  6  7	9
--- 880
0  1  2  3  4  5  6  7	9
--- 890
0  1  2  3  4  5  6  7	9
--- 900
0  1  2  3  4  5  6  7	9
--- 910
0  1  2  3  4  5  6  7	9
--- 920
0  1  2  3  4  5  6  7	9
--- 930
0  1  2  3  4  5  6  7	9
--- 940
0  1  2  3  4  5  6  7	9
--- 950
0  1  2  3  4  5  6  7	9
--- 960
0  1  2  3  4  5  6  7	9
--- 970
0  1  2  3  4  5  6  7	9
--- 980
0  1  2  3  4  5  6  7	9
--- 990
0  1  2  3  4  5  6  7	9
===
total 0
lrwx------ 1 devuser grp01 64 Nov 27 18:58 0 -> /dev/pts/3
lrwx------ 1 devuser grp01 64 Nov 27 18:58 1 -> /dev/pts/3
lrwx------ 1 devuser grp01 64 Nov 27 18:58 2 -> /dev/pts/3
lr-x------ 1 devuser grp01 64 Nov 27 18:58 3 -> pipe:[305207029]
l-wx------ 1 devuser grp01 64 Nov 27 18:58 4 -> pipe:[305207029]
lrwx------ 1 devuser grp01 64 Nov 27 18:58 5 -> socket:[305207030]
lrwx------ 1 devuser grp01 64 Nov 27 18:59 6 -> socket:[305217326]
lrwx------ 1 devuser grp01 64 Nov 27 18:59 7 -> socket:[305224209]
lrwx------ 1 devuser grp01 64 Nov 27 18:59 9 -> socket:[305213256]
---

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.