Remove JID cache, to better test for performance.
This commit is contained in:
parent
8335c08782
commit
c29fc39ef1
4 changed files with 20 additions and 60 deletions
|
@ -57,12 +57,12 @@ class BaseXMPP(XMLStream):
|
||||||
self.stream_id = None
|
self.stream_id = None
|
||||||
|
|
||||||
#: The JabberID (JID) requested for this connection.
|
#: The JabberID (JID) requested for this connection.
|
||||||
self.requested_jid = JID(jid, cache_lock=True)
|
self.requested_jid = JID(jid)
|
||||||
|
|
||||||
#: The JabberID (JID) used by this connection,
|
#: The JabberID (JID) used by this connection,
|
||||||
#: as set after session binding. This may even be a
|
#: as set after session binding. This may even be a
|
||||||
#: different bare JID than what was requested.
|
#: different bare JID than what was requested.
|
||||||
self.boundjid = JID(jid, cache_lock=True)
|
self.boundjid = JID(jid)
|
||||||
|
|
||||||
self._expected_server_name = self.boundjid.host
|
self._expected_server_name = self.boundjid.host
|
||||||
self._redirect_attempts = 0
|
self._redirect_attempts = 0
|
||||||
|
@ -638,7 +638,7 @@ class BaseXMPP(XMLStream):
|
||||||
def set_jid(self, jid):
|
def set_jid(self, jid):
|
||||||
"""Rip a JID apart and claim it as our own."""
|
"""Rip a JID apart and claim it as our own."""
|
||||||
log.debug("setting jid to %s", jid)
|
log.debug("setting jid to %s", jid)
|
||||||
self.boundjid = JID(jid, cache_lock=True)
|
self.boundjid = JID(jid)
|
||||||
|
|
||||||
def getjidresource(self, fulljid):
|
def getjidresource(self, fulljid):
|
||||||
if '/' in fulljid:
|
if '/' in fulljid:
|
||||||
|
|
|
@ -52,7 +52,7 @@ class FeatureBind(BasePlugin):
|
||||||
iq.send(callback=self._on_bind_response)
|
iq.send(callback=self._on_bind_response)
|
||||||
|
|
||||||
def _on_bind_response(self, response):
|
def _on_bind_response(self, response):
|
||||||
self.xmpp.boundjid = JID(response['bind']['jid'], cache_lock=True)
|
self.xmpp.boundjid = JID(response['bind']['jid'])
|
||||||
self.xmpp.bound = True
|
self.xmpp.bound = True
|
||||||
self.xmpp.event('session_bind', self.xmpp.boundjid)
|
self.xmpp.event('session_bind', self.xmpp.boundjid)
|
||||||
self.xmpp.session_bind_event.set()
|
self.xmpp.session_bind_event.set()
|
||||||
|
|
|
@ -16,13 +16,11 @@ from __future__ import unicode_literals
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import stringprep
|
import stringprep
|
||||||
import threading
|
|
||||||
import encodings.idna
|
import encodings.idna
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from slixmpp.util import stringprep_profiles
|
from slixmpp.util import stringprep_profiles
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
#: These characters are not allowed to appear in a JID.
|
#: These characters are not allowed to appear in a JID.
|
||||||
ILLEGAL_CHARS = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r' + \
|
ILLEGAL_CHARS = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r' + \
|
||||||
|
@ -69,25 +67,6 @@ JID_UNESCAPE_TRANSFORMATIONS = {'\\20': ' ',
|
||||||
'\\40': '@',
|
'\\40': '@',
|
||||||
'\\5c': '\\'}
|
'\\5c': '\\'}
|
||||||
|
|
||||||
JID_CACHE = OrderedDict()
|
|
||||||
JID_CACHE_LOCK = threading.Lock()
|
|
||||||
JID_CACHE_MAX_SIZE = 1024
|
|
||||||
|
|
||||||
def _cache(key, parts, locked):
|
|
||||||
JID_CACHE[key] = (parts, locked)
|
|
||||||
if len(JID_CACHE) > JID_CACHE_MAX_SIZE:
|
|
||||||
with JID_CACHE_LOCK:
|
|
||||||
while len(JID_CACHE) > JID_CACHE_MAX_SIZE:
|
|
||||||
found = None
|
|
||||||
for key, item in JID_CACHE.items():
|
|
||||||
if not item[1]: # if not locked
|
|
||||||
found = key
|
|
||||||
break
|
|
||||||
if not found: # more than MAX_SIZE locked
|
|
||||||
# warn?
|
|
||||||
break
|
|
||||||
del JID_CACHE[found]
|
|
||||||
|
|
||||||
# pylint: disable=c0103
|
# pylint: disable=c0103
|
||||||
#: The nodeprep profile of stringprep used to validate the local,
|
#: The nodeprep profile of stringprep used to validate the local,
|
||||||
#: or username, portion of a JID.
|
#: or username, portion of a JID.
|
||||||
|
@ -436,7 +415,6 @@ class JID(object):
|
||||||
|
|
||||||
# pylint: disable=W0212
|
# pylint: disable=W0212
|
||||||
def __init__(self, jid=None, **kwargs):
|
def __init__(self, jid=None, **kwargs):
|
||||||
locked = kwargs.get('cache_lock', False)
|
|
||||||
in_local = kwargs.get('local', None)
|
in_local = kwargs.get('local', None)
|
||||||
in_domain = kwargs.get('domain', None)
|
in_domain = kwargs.get('domain', None)
|
||||||
in_resource = kwargs.get('resource', None)
|
in_resource = kwargs.get('resource', None)
|
||||||
|
@ -444,40 +422,23 @@ class JID(object):
|
||||||
if in_local or in_domain or in_resource:
|
if in_local or in_domain or in_resource:
|
||||||
parts = (in_local, in_domain, in_resource)
|
parts = (in_local, in_domain, in_resource)
|
||||||
|
|
||||||
# only check cache if there is a jid string, or parts, not if there
|
if not jid:
|
||||||
# are both
|
parsed_jid = (None, None, None)
|
||||||
self._jid = None
|
elif not isinstance(jid, JID):
|
||||||
key = None
|
parsed_jid = _parse_jid(jid)
|
||||||
if (jid is not None) and (parts is None):
|
else:
|
||||||
if isinstance(jid, JID):
|
parsed_jid = jid._jid
|
||||||
# it's already good to go, and there are no additions
|
|
||||||
self._jid = jid._jid
|
|
||||||
return
|
|
||||||
key = jid
|
|
||||||
self._jid, locked = JID_CACHE.get(jid, (None, locked))
|
|
||||||
elif jid is None and parts is not None:
|
|
||||||
key = parts
|
|
||||||
self._jid, locked = JID_CACHE.get(parts, (None, locked))
|
|
||||||
if not self._jid:
|
|
||||||
if not jid:
|
|
||||||
parsed_jid = (None, None, None)
|
|
||||||
elif not isinstance(jid, JID):
|
|
||||||
parsed_jid = _parse_jid(jid)
|
|
||||||
else:
|
|
||||||
parsed_jid = jid._jid
|
|
||||||
|
|
||||||
local, domain, resource = parsed_jid
|
local, domain, resource = parsed_jid
|
||||||
|
|
||||||
if 'local' in kwargs:
|
if 'local' in kwargs:
|
||||||
local = _escape_node(in_local)
|
local = _escape_node(in_local)
|
||||||
if 'domain' in kwargs:
|
if 'domain' in kwargs:
|
||||||
domain = _validate_domain(in_domain)
|
domain = _validate_domain(in_domain)
|
||||||
if 'resource' in kwargs:
|
if 'resource' in kwargs:
|
||||||
resource = _validate_resource(in_resource)
|
resource = _validate_resource(in_resource)
|
||||||
|
|
||||||
self._jid = (local, domain, resource)
|
self._jid = (local, domain, resource)
|
||||||
if key:
|
|
||||||
_cache(key, self._jid, locked)
|
|
||||||
|
|
||||||
def unescape(self):
|
def unescape(self):
|
||||||
"""Return an unescaped JID object.
|
"""Return an unescaped JID object.
|
||||||
|
|
|
@ -128,9 +128,8 @@ class XEP_0078(BasePlugin):
|
||||||
|
|
||||||
self.xmpp.authenticated = True
|
self.xmpp.authenticated = True
|
||||||
|
|
||||||
self.xmpp.boundjid = JID(self.xmpp.requested_jid,
|
self.xmpp.boundjid = JID(self.xmpp.requested_jid)
|
||||||
resource=resource,
|
self.xmpp.boundjid.resource = resource
|
||||||
cache_lock=True)
|
|
||||||
self.xmpp.event('session_bind', self.xmpp.boundjid)
|
self.xmpp.event('session_bind', self.xmpp.boundjid)
|
||||||
|
|
||||||
log.debug("Established Session")
|
log.debug("Established Session")
|
||||||
|
|
Loading…
Reference in a new issue