0

I'm testing a gateway server for websocket client connection. I currently open 10000 clients to connect and send messages to my gateway server, and it echos back all the messages. When I type 'ctrl + c' to stop the process, it takes a long time to stop, and so much stacktrace info. So I want to count the number of the pending task in the loop, and find a solution to stop ioloop quicker without that stacktrace info

I can't find any api about ioloop task counting in https://www.tornadoweb.org/en/stable/ioloop.html , so I ask here.

Server Side Code:

def create_application():
    return tornado.web.Application([(r'/', WebSocketHandler)])

if __name__ == '__main__':
    app = create_application()
    app.listen(60017)

Client Side Code:

if __name__=='__main__':
    try:
        for i in range(1, 10000):
            wsc = WSClient('ws://127.0.0.1:60017', 'pname_' + str(i))
            wsc.start()
            ws_list.append(wsc)
            print('ws_client pname[%s] started!!!'%('pname_' + str(i)))
        tornado.ioloop.IOLoop.current().add_timeout(time.time() + 1, counting_packs)
        tornado.ioloop.IOLoop.current().start()

    except Exception as e:
        print(str(e))

I expect to count the num of pending task every second... It would be appreciated if anyone can tell me how to do it. Thanks a lot!!!

Badboy Lin
  • 110
  • 7

1 Answers1

0

Tornado does not currently offer any way to find out how many tasks are pending.

If you just want to suppress the stack traces when you press ctrl-c and exit as quickly as possible, you can run signal.signal(signal.SIGINT, signal.SIG_DFL). This will also mean that you can't catch KeyboardInterrupt and recover from it.

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
  • One more small problem, I was testing my program, which receives about 5000 packs from clients per second, and it runs a timeout task each second to print out how many packs have been recv and send. But from the output I can see this task runs not exactly one second at a time, often delays upto 2 seconds. I'm not sure how to make it more puntual... I've already using less coroutine and blocks coroutine as less as posible. Any recommendation ? here are some sample output: interval is 1.9211 recv packs from ws:5857 send packs to ws:2766 – Badboy Lin Apr 11 '19 at 12:30