-
Notifications
You must be signed in to change notification settings - Fork 0
/
ca_startup.py
70 lines (58 loc) · 1.89 KB
/
ca_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
58
59
60
61
62
63
64
65
66
67
68
69
70
# coding: utf-8
import os
import errno
import tornado.options
from tornado.options import define, options
import etcd
from tornado.log import gen_log
from tornado.util import errno_from_exception
define("port", default=20000, help="run on the given port", type=int)
define("etcd", default="localhost", help="etcd hostname", type=str)
define("ca_path", default="./uv/ca.out", help="path of uv ca", type=str)
tornado.options.parse_command_line()
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
eclient = etcd.Client(host=options.etcd, port=2379)
end_points = []
uv_argv = []
for e in eclient.read('/dubbomesh/com.alibaba.dubbo.performance.demo.provider.IHelloService').children:
s = e.key[69:].split(':')
gen_log.info('get endpoint: {0}, {1}, {2}'.format(s[0], s[1], e.value))
end_points.append((s[0], int(s[1]), int(e.value)))
uv_argv.extend([s[0], s[1], e.value])
print 'cpu count:', cpu_count()
instance_count = 2
print 'start up {0} instances'.format(instance_count)
children = {}
for i in range(instance_count):
pid = os.fork()
if pid == 0:
os.execv(options.ca_path, uv_argv)
else:
children[pid] = i
while children:
try:
pid, status = os.wait()
except OSError as e:
if errno_from_exception(e) == errno.EINTR:
continue
raise
gen_log.warning("pid: {0} finish, status: {1}".format(pid, status))
children.pop(pid)