Files
zulip/zerver/tornado/sharding.py
Tim Abbott 220620e7cf sharding: Add basic sharding configuration for Tornado.
This allows straight-forward configuration of realm-based Tornado
sharding through simply editing /etc/zulip/zulip.conf to configure
shards and running scripts/refresh-sharding-and-restart.

Co-Author-By: Mateusz Mandera <mateusz.mandera@zulip.com>
2020-05-20 13:47:20 -07:00

29 lines
854 B
Python

from django.conf import settings
from zerver.models import Realm
import json
import os
shard_map = {}
if os.path.exists("/etc/zulip/sharding.json"):
with open("/etc/zulip/sharding.json") as f:
shard_map = json.loads(f.read())
def get_tornado_port(realm: Realm) -> int:
if settings.TORNADO_SERVER is None:
return 9993
if settings.TORNADO_PROCESSES == 1:
return int(settings.TORNADO_SERVER.split(":")[-1])
return shard_map.get(realm.host, 9800)
def get_tornado_uri(realm: Realm) -> str:
if settings.TORNADO_PROCESSES == 1:
return settings.TORNADO_SERVER
port = get_tornado_port(realm)
return "http://127.0.0.1:%d" % (port,)
def notify_tornado_queue_name(port: int) -> str:
if settings.TORNADO_PROCESSES == 1:
return "notify_tornado"
return "notify_tornado_port_%d" % (port,)