def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-l", "--listen", dest="host", default="0.0.0.0", help="the ip interface to bind") parser.add_option("-p", "--port", default=7902, type=int, help="which port to listen") parser.add_option("-d", "--daemon", action="store_true", help="run in daemon", default=False) (options, args) = parser.parse_args() cfg = {"localhost:7901":range(16), "localhost:7902":range(16), "localhost:7903":range(16)} store = Client(cfg, 16) print "server listening on %s:%s" % (options.host, options.port) server = api.tcp_listener((options.host, options.port)) util.set_reuse_addr(server) while True: try: new_sock, address = server.accept() except KeyboardInterrupt: break api.spawn(handler, store, new_sock) print 'close listener ...' server.close()
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-l", "--listen", dest="host", default="0.0.0.0", help="the ip interface to bind") parser.add_option("-p", "--port", default=7902, type=int, help="which port to listen") # parser.add_option("-d", "--daemon", action="store_true", # help="run in daemon", default=False) parser.add_option("-H", "--home", default="beansdb", help="the database path") parser.add_option("-c", "--count", default=16, type=int, help="number of db file, power of 16") parser.add_option("-s", "--start", default=0, type=int, help="start index of db file") parser.add_option("-e", "--end", default=-1, type=int, help="last end of db file, -1 means no limit") parser.add_option("-n", "--limit", default=100, type=int, help="diffs limit to do db scan") parser.add_option("-t", "--threads", type=int, default=20, help="number of IO threads") (options, args) = parser.parse_args() store = (HStore(options.home, int(math.log(options.count, 16)), options.start, options.end)) #store.check(options.limit, nonblocking=True) api.spawn(tpool.execute, store.check, options.limit) # check in thread pool api.spawn(tpool.execute, flush, store) print "server listening on %s:%s" % (options.host, options.port) server = api.tcp_listener((options.host, options.port)) util.set_reuse_addr(server) while True: try: new_sock, address = server.accept() except KeyboardInterrupt: break api.spawn(handler, store, new_sock, new_sock.makefile('r'), new_sock.makefile('w')) global quit quit = True print 'close listener ...' server.close() print 'stop checker thread ...' store.stop_check() print 'stop worker threads ...' tpool.killall() print 'close store...' store.close()