def setUp(self): self.topic = b'test-topic' self.channel = b'test-channel' self.nsqd = nsqd.Client('http://localhost:14151') self.nsqlookupd = nsqlookupd.Client('http://localhost:14161') # Create this topic self.nsqlookupd.create_topic(self.topic) self.nsqlookupd.create_channel(self.topic, self.channel) self.nsqd.create_topic(self.topic) self.nsqd.create_channel(self.topic, self.channel)
def test_stats(self): '''Can effectively grab all the stats.''' # Create some topics, channels, and messages on the first nsqd instance client = nsqd.Client('http://localhost:14151') topics = [ 'topic-on-both-instances', 'topic-with-channels', 'topic-without-channels' ] for topic in topics: client.create_topic(topic) client.mpub(topic, [six.text_type(i).encode() for i in range(len(topic))]) client.create_channel('topic-with-channels', 'channel') # Create a topic and messages on the second nsqd isntance client = nsqd.Client('http://localhost:14153') client.create_topic('topic-on-both-instances') client.mpub(topic, [six.text_type(i).encode() for i in range(10)]) # Check the stats self.assertFixture( 'test/fixtures/test_stats/TestStats/stats', [list(x) for x in Nsqlookupd('http://localhost:14161').stats])
def __init__(self, port, nsqlookupd): self._client = nsqd.Client('http://localhost:%s' % (port + 1)) options = { 'data-path': 'test/tmp', 'deflate': 'true', 'snappy': 'true', 'tls-cert': 'test/fixtures/certificates/cert.pem', 'tls-key': 'test/fixtures/certificates/key.pem', 'broadcast-address': 'localhost', 'tcp-address': '0.0.0.0:%s' % (port), 'http-address': '0.0.0.0:%s' % (port + 1), 'lookupd-tcp-address': '127.0.0.1:%s' % nsqlookupd } args = ['--%s=%s' % (k, v) for k, v in options.items()] ProcessWrapper.__init__(self, 'nsqd', *args)
def basic(topic='topic', channel='channel', count=1e6, size=10, gevent=False, max_in_flight=2500, profile=False): '''Basic benchmark''' if gevent: from gevent import monkey monkey.patch_all() # Check the types of the arguments count = int(count) size = int(size) max_in_flight = int(max_in_flight) from nsq.http import nsqd from nsq.reader import Reader print('Publishing messages...') for batch in grouper(messages(count, size), 1000): nsqd.Client('http://localhost:4151').mpub(topic, batch) print('Consuming messages') client = Reader(topic, channel, nsqd_tcp_addresses=['localhost:4150'], max_in_flight=max_in_flight) with closing(client): start = -time.time() if profile: with profiler(): for message in islice(client, count): message.fin() else: for message in islice(client, count): message.fin() start += time.time() print('Finished %i messages in %fs (%5.2f messages / second)' % (count, start, count / start))
def setUp(self): self.client = nsqd.Client('http://foo:1')