-
Notifications
You must be signed in to change notification settings - Fork 0
/
pa_startup.py
57 lines (48 loc) · 1.6 KB
/
pa_startup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
import logging.config
import socket
import time
import os
import tornado.options
from tornado.options import define, options
from tornado.log import gen_log
import etcd
from utils import bytes2int, get_ip
try:
import multiprocessing
except ImportError:
# Multiprocessing is not available on Google App Engine.
multiprocessing = None
def cpu_count():
"""Returns the number of processors on this machine."""
if multiprocessing is None:
return 1
try:
return multiprocessing.cpu_count()
except NotImplementedError:
pass
try:
return os.sysconf("SC_NPROCESSORS_CONF")
except (AttributeError, ValueError):
pass
gen_log.error("Could not detect number of processors; assuming 1")
return 1
define("port", default=30000, help="run on the given port", type=int)
define("weight", default=1, help="weight", type=int)
define("etcd", default="localhost", help="etcd hostname", type=str)
tornado.options.parse_command_line()
client = etcd.Client(host=options.etcd, port=2379)
client.write('/dubbomesh/com.alibaba.dubbo.performance.demo.provider.IHelloService/{0}:{1}'.format(get_ip(), options.port), options.weight)
gen_log.info('register with {0}:{1} [{2}]'.format(get_ip(), options.port, options.weight))
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('127.0.0.1', 20880))
s.close()
gen_log.info("connect to 20880 success")
break
except socket.error:
gen_log.info("connect to 20880 fail, wait a second")
time.sleep(0.2)
pass
# TODO: startup pa