<commit_before>'''
Created on 2016/9/20

:author: hubo
'''
from __future__ import print_function
from vlcp.server import main
from vlcp.event import Client
from vlcp.server.module import Module
from vlcp.config import defaultconfig
from vlcp.protocol.zookeeper import ZooKeeper, ZooKeeperConnectionStateEvent,\
    ZooKeeperWatcherEvent
import vlcp.utils.zookeeper as zk
from vlcp.utils.zkclient import ZooKeeperClient, ZooKeeperSessionStateChanged
from vlcp.event.runnable import RoutineContainer
from namedstruct import dump
from pprint import pprint

@defaultconfig
class TestModule(Module):
    _default_serverlist = ['tcp://localhost:3181/','tcp://localhost:3182/','tcp://localhost:3183/']
    def __init__(self, server):
        Module.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def main(self):
        clients = [ZooKeeperClient(self.apiroutine, self.serverlist) for _ in range(0,10)]
        def test_loop(number):
            maindir = ('vlcptest_' + str(number)).encode('utf-8')
            client = clients[number % len(clients)]
            for _ in range(0, 100):
                for m in client.requests([zk.multi(
                                                zk.multi_create(maindir, b'test'),
                                                zk.multi_create(maindir + b'/subtest', 'test2')
                                            ),
                                          zk.getchildren2(maindir, True)], self.apiroutine):
                    yield m
                for m in client.requests([zk.multi(
                                                zk.multi_delete(maindir + b'/subtest'),
                                                zk.multi_delete(maindir)),
                                          zk.getchildren2(maindir, True)], self.apiroutine):
                    yield m
        from time import time
        starttime = time()
        for m in self.apiroutine.executeAll([test_loop(i) for i in range(0, 100)]):
            yield m
        print('10000 loops in %r seconds, with %d connections' % (time() - starttime, len(clients)))
        
if __name__ == '__main__':
    main()
    <commit_msg>start connection<commit_after>'''
Created on 2016/9/20

:author: hubo
'''
from __future__ import print_function
from vlcp.server import main
from vlcp.event import Client
from vlcp.server.module import Module
from vlcp.config import defaultconfig
from vlcp.protocol.zookeeper import ZooKeeper, ZooKeeperConnectionStateEvent,\
    ZooKeeperWatcherEvent
import vlcp.utils.zookeeper as zk
from vlcp.utils.zkclient import ZooKeeperClient, ZooKeeperSessionStateChanged
from vlcp.event.runnable import RoutineContainer
from namedstruct import dump
from pprint import pprint

@defaultconfig
class TestModule(Module):
    _default_serverlist = ['tcp://localhost:3181/','tcp://localhost:3182/','tcp://localhost:3183/']
    def __init__(self, server):
        Module.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def main(self):
        clients = [ZooKeeperClient(self.apiroutine, self.serverlist) for _ in range(0,10)]
        for c in clients:
            c.start()
        def test_loop(number):
            maindir = ('vlcptest_' + str(number)).encode('utf-8')
            client = clients[number % len(clients)]
            for _ in range(0, 100):
                for m in client.requests([zk.multi(
                                                zk.multi_create(maindir, b'test'),
                                                zk.multi_create(maindir + b'/subtest', 'test2')
                                            ),
                                          zk.getchildren2(maindir, True)], self.apiroutine):
                    yield m
                for m in client.requests([zk.multi(
                                                zk.multi_delete(maindir + b'/subtest'),
                                                zk.multi_delete(maindir)),
                                          zk.getchildren2(maindir, True)], self.apiroutine):
                    yield m
        from time import time
        starttime = time()
        for m in self.apiroutine.executeAll([test_loop(i) for i in range(0, 100)]):
            yield m
        print('10000 loops in %r seconds, with %d connections' % (time() - starttime, len(clients)))
        for c in clients:
            for m in c.shutdown():
                yield m
        
if __name__ == '__main__':
    main()
    
{'fraction_non_alphanumeric': 0.09657387580299785, 'fraction_numerical': 0.01670235546038544, 'mean_word_length': 1.878003696857671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6306999', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1259, 'n_words': 308}