make the statsd backend a little faster, too
This commit is contained in:
@@ -33,6 +33,7 @@ def clientloop():
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
tomograph.config.set_backends(sys.argv[1:])
|
||||
cProfile.run('clientloop()', 'tomo-bench')
|
||||
#cProfile.run('clientloop()', 'tomo-bench')
|
||||
clientloop()
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
# limitations under the License. See accompanying LICENSE file.
|
||||
|
||||
from tomograph import config
|
||||
from tomograph import cache
|
||||
|
||||
import logging
|
||||
import socket
|
||||
@@ -18,12 +19,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
hostname_cache = cache.Cache(socket.gethostbyname)
|
||||
|
||||
def send(span):
|
||||
|
||||
def statsd_send(name, value, units):
|
||||
stat = str(name).replace(' ', '-') + ':' + str(int(value)) + '|' + str(units)
|
||||
logger.info('sending stat {0}'.format(stat))
|
||||
udp_socket.sendto(stat, (config.statsd_host, config.statsd_port))
|
||||
#logger.info('sending stat {0}'.format(stat))
|
||||
udp_socket.sendto(stat, (hostname_cache.get(config.statsd_host), config.statsd_port))
|
||||
|
||||
def server_name(note):
|
||||
address = note.address.replace('.', '-')
|
||||
@@ -38,4 +41,6 @@ def send(span):
|
||||
# a count stat for each note
|
||||
for note in span.notes:
|
||||
stat_name = server_name(note) + '.' + span.name + '.' + str(note.value)
|
||||
#print "before"
|
||||
statsd_send(stat_name, 1, 'c')
|
||||
#print "after"
|
||||
|
||||
@@ -17,6 +17,7 @@ from thrift.transport import TSocket
|
||||
from thrift.protocol import TBinaryProtocol
|
||||
|
||||
from tomograph import config
|
||||
from tomograph import cache
|
||||
|
||||
import base64
|
||||
import StringIO
|
||||
@@ -27,30 +28,11 @@ import socket
|
||||
import sys
|
||||
import traceback
|
||||
import atexit
|
||||
import threading
|
||||
|
||||
scribe_sender = sender.ScribeSender()
|
||||
atexit.register(scribe_sender.close)
|
||||
|
||||
class Cache(object):
|
||||
def __init__(self, thunk, size_limit=1000):
|
||||
self._map = {}
|
||||
self._thunk = thunk
|
||||
self._size_limit = size_limit
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def get(self, k):
|
||||
with self._lock:
|
||||
if self._map.has_key(k):
|
||||
return self._map[k]
|
||||
else:
|
||||
while len(self._map) >= self._size_limit:
|
||||
self._map.popitem()
|
||||
v = self._thunk(k)
|
||||
self._map[k] = v
|
||||
return v
|
||||
|
||||
hostname_cache = Cache(socket.gethostbyname)
|
||||
hostname_cache = cache.Cache(socket.gethostbyname)
|
||||
|
||||
def send(span):
|
||||
|
||||
|
||||
31
tomograph/cache.py
Normal file
31
tomograph/cache.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Copyright (c) 2012 Yahoo! Inc. All rights reserved.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
||||
# may not use this file except in compliance with the License. You may
|
||||
# obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 Unless required by
|
||||
# applicable law or agreed to in writing, software distributed under
|
||||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
|
||||
# OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and
|
||||
# limitations under the License. See accompanying LICENSE file.
|
||||
|
||||
import threading
|
||||
|
||||
class Cache(object):
|
||||
def __init__(self, thunk, size_limit=1000):
|
||||
self._map = {}
|
||||
self._thunk = thunk
|
||||
self._size_limit = size_limit
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def get(self, k):
|
||||
with self._lock:
|
||||
if self._map.has_key(k):
|
||||
return self._map[k]
|
||||
else:
|
||||
while len(self._map) >= self._size_limit:
|
||||
self._map.popitem()
|
||||
v = self._thunk(k)
|
||||
self._map[k] = v
|
||||
return v
|
||||
|
||||
@@ -16,7 +16,6 @@ logger = logging.getLogger(__name__)
|
||||
enabled_backends = ['tomograph.backends.zipkin',
|
||||
'tomograph.backends.statsd',
|
||||
'tomograph.backends.log']
|
||||
#enabled_backends = []
|
||||
backend_modules = []
|
||||
|
||||
def set_backends(backends):
|
||||
|
||||
Reference in New Issue
Block a user