Created
November 21, 2015 19:27
-
-
Save soumyadipdm/1ad86c34b729fd825f57 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
import sys | |
import time | |
import numpy as np | |
import json | |
CF_HASHTABLESIZE = 8192 | |
def stringhash(s, seed, max): | |
# Implementation of StringHash() from: | |
# https://github.com/lpefferkorn/cfe-rsplaytime/blob/master/cfe-rsplaytime.py | |
h = np.uint32(seed) | |
for i in bytearray(s): | |
h += np.uint32(i) | |
h += np.uint32(h << 10) | |
h ^= np.uint32(h >> 6) | |
h += np.uint32(h << 3) | |
h ^= np.uint32(h >> 11) | |
h += np.uint32(h << 15) | |
return np.uint32(h & (max - 1)) | |
'''def get_index_changed(hostname, ip, list_length, ti): | |
# changed calculation of hash time as seed | |
ti -= ti%CF_HASHTABLESIZE | |
hashstr = '{0}+{1}+{2}'.format(hostname, ip, ti) | |
hash_value = stringhash(hashstr, 0, CF_HASHTABLESIZE) | |
return int(list_length * hash_value / float(CF_HASHTABLESIZE)) | |
''' | |
def get_index_changed(hostname, ip, list_length): | |
# original calculation of hash | |
hashstr = '{0}+{1}+{2}'.format(hostname, ip, 0) | |
hash_value = stringhash(hashstr, 0, CF_HASHTABLESIZE) | |
hash_value = stringhash(hashstr, hash_value, CF_HASHTABLESIZE) | |
return int(list_length * hash_value / float(CF_HASHTABLESIZE)) | |
def get_index_original(hostname, ip, list_length): | |
# original calculation of hash | |
hashstr = '{0}+{1}+{2}'.format(hostname, ip, 0) | |
hash_value = stringhash(hashstr, 0, CF_HASHTABLESIZE) | |
return int(list_length * hash_value / float(CF_HASHTABLESIZE)) | |
def get_splaytime(hostname, ip): | |
# implementation of GetSplay() in cf-execd/execd-config.c | |
hashstr = '{0}+{1}+{2}'.format(hostname, ip, 0) | |
hash_value = stringhash(hashstr, 0, CF_HASHTABLESIZE) | |
splay = np.float64(hash_value / float(CF_HASHTABLESIZE)) | |
return int(4*60*splay) | |
def main(): | |
mpses = ['mps1', 'mps2', 'mps3', 'mps4'] | |
data = {} | |
#ti = time.time() | |
# hostlist is a file with hostname ip per line | |
with open('hostlist') as hostlist: | |
for line in hostlist: | |
hostname, ip = line.split() | |
splaytime = get_splaytime(hostname, ip) | |
mps_orig = mpses[get_index_original(hostname, ip, len(mpses))] | |
select_class_changed = mpses[get_index_changed(hostname, ip, len(mpses))] | |
if splaytime not in data: | |
data[splaytime] = [] | |
data[splaytime].append({'hostname': hostname, 'select_class_original': mps_orig, 'select_class_changed': select_class_changed }) | |
#print json.dumps(data, indent=2, sort_keys=True) | |
mps_count = [] | |
for seconds in sorted(data.keys()): | |
if seconds%60 == 0: | |
temp_data = { 'select_class_original': {}, 'select_class_changed': {} } | |
mps_count.append(temp_data) | |
for i in ['select_class_original', 'select_class_changed']: | |
for j in data[seconds]: | |
if j[i] not in temp_data[i]: | |
temp_data[i][j[i]] = 0 | |
temp_data[i][j[i]] += 1 | |
for minute, methods in enumerate(mps_count): | |
print "During Minute: {0}".format(minute+1) | |
for method in methods: | |
print "{0}:".format(method) | |
for mps in methods[method]: | |
print "{0} was selected by {1} hosts".format(mps, methods[method][mps]) | |
print "" | |
print "" | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment