Skip to content

Instantly share code, notes, and snippets.

@rimms
Created March 27, 2014 11:51
Show Gist options
  • Save rimms/9805872 to your computer and use it in GitHub Desktop.
Save rimms/9805872 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
from jubatus.common import Datum
from jubatus.recommender import client
NAME = "test";
PORT = 9199
def get_pid(port):
return int(subprocess.check_output(['lsof', '-i', ':' + str(port)]).split()[10])
def memstat(pid):
stat = {}
for line in open('/proc/' + str(pid) + '/status', 'r'):
if line.startswith('Vm'):
key, value = line.split()[:2]
stat[key.replace(':', '')] = int(value)
return stat['VmRSS']
if __name__ == '__main__':
pid = get_pid(PORT)
recommender = client.Recommender("127.0.0.1", PORT, NAME)
n = 0
for i in range(1, 4):
print '\ncycle' + str(i)
print 'Queries RSS(KB)'
print '------- -------'
print str(n).zfill(7), memstat(pid)
for line in open('ml-10M100K/ratings10000.dat'):
userid, movieid, rating = line.split('::')[:3]
datum = Datum({str(movieid): float(rating)})
recommender.update_row(userid, datum)
n = n + 1
if (n % 1000 == 0):
print str(n).zfill(7), memstat(pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment