Skip to content

Commit cc9f844

Browse files
committed
Improve startup time by prelocating libjemalloc
This requires apache/cassandra-ccm#519 in order to work correctly.
1 parent 4fad0ca commit cc9f844

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Diff for: dtest.py

+25
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@
115115
CASSANDRA_VERSION_FROM_BUILD = get_version_from_build(CASSANDRA_DIR)
116116

117117

118+
# Determine the location of the libjemalloc jar so that we can specify it
119+
# through environment variables when start Cassandra. This reduces startup
120+
# time, making the dtests run faster.
121+
def find_libjemalloc():
122+
if is_win():
123+
# let the normal bat script handle finding libjemalloc
124+
return ""
125+
126+
this_dir = os.path.dirname(os.path.realpath(__file__))
127+
script = os.path.join(this_dir, "findlibjemalloc.sh")
128+
try:
129+
p = subprocess.Popen([script], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
130+
stdout, stderr = p.communicate()
131+
if stderr or not stdout:
132+
return "-" # tells C* not to look for libjemalloc
133+
else:
134+
return stdout
135+
except Exception, exc:
136+
print "Failed to run script to prelocate libjemalloc ({}): {}".format(script, exc)
137+
return ""
138+
139+
CASSANDRA_LIBJEMALLOC = find_libjemalloc()
140+
141+
118142
class expect_control_connection_failures(object):
119143
"""
120144
We're just using a class here as a one-off object with a filter method, for
@@ -270,6 +294,7 @@ def _get_cluster(self, name='test'):
270294
cluster.set_configuration_options(values={'memtable_allocation_type': 'offheap_objects'})
271295

272296
cluster.set_datadir_count(DATADIR_COUNT)
297+
cluster.set_environment_variable('CASSANDRA_LIBJEMALLOC', CASSANDRA_LIBJEMALLOC)
273298

274299
return cluster
275300

Diff for: findlibjemalloc.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
# taken from bin/cassandra
4+
5+
find_library()
6+
{
7+
pattern=$1
8+
path=$(echo ${2} | tr ":" " ")
9+
find $path -regex "$pattern" -print 2>/dev/null | head -n 1
10+
}
11+
12+
case "`uname -s`" in
13+
Linux)
14+
which ldconfig > /dev/null 2>&1
15+
if [ $? = 0 ] ; then
16+
# e.g. for CentOS
17+
dirs="/lib64 /lib /usr/lib64 /usr/lib `ldconfig -v 2>/dev/null | grep -v '^\s' | sed 's/^\([^:]*\):.*$/\1/'`"
18+
else
19+
# e.g. for Debian, OpenSUSE
20+
dirs="/lib64 /lib /usr/lib64 /usr/lib `cat /etc/ld.so.conf /etc/ld.so.conf.d/*.conf | grep '^/'`"
21+
fi
22+
dirs=`echo $dirs | tr " " ":"`
23+
CASSANDRA_LIBJEMALLOC=$(find_library '.*/libjemalloc\.so\(\.1\)*' $dirs)
24+
;;
25+
Darwin)
26+
CASSANDRA_LIBJEMALLOC=$(find_library '.*/libjemalloc\.dylib' $DYLD_LIBRARY_PATH:${DYLD_FALLBACK_LIBRARY_PATH-$HOME/lib:/usr/local/lib:/lib:/usr/lib})
27+
;;
28+
esac
29+
30+
if [ ! -z $CASSANDRA_LIBJEMALLOC ] ; then
31+
echo $(CASSANDRA_LIBJEMALLOC)
32+
exit 0
33+
else
34+
exit 1
35+
fi

0 commit comments

Comments
 (0)