Permalink
Browse files

upgraded deliverability tests in Python and fixed timeout issue in Tw…

…isted API.
  • Loading branch information...
1 parent 3a865b1 commit 88ca393ff7ca460416f5201f20231a12a091f1f6 @stephenlb stephenlb committed Jun 30, 2012
Showing with 116 additions and 56 deletions.
  1. +3 −1 python-tornado/Pubnub.py
  2. +54 −26 python-tornado/tests/delivery.py
  3. +5 −3 python-twisted/Pubnub.py
  4. +54 −26 python-twisted/tests/delivery.py
View
@@ -34,6 +34,8 @@ class Pubnub():
def stop(self): ioloop.stop()
def start(self): ioloop.start()
+ def timeout( self, callback, delay ):
+ ioloop.add_timeout( time.time()+float(delay), callback )
def __init__(
self,
@@ -432,7 +434,7 @@ def complete(response) :
callback(obj)
## Send Request Expecting JSON Response
- http = tornado.httpclient.AsyncHTTPClient(max_clients=100)
+ http = tornado.httpclient.AsyncHTTPClient(max_clients=1000)
request = tornado.httpclient.HTTPRequest( url, 'GET', dict({
'V' : '3.1',
'User-Agent' : 'Python-Tornado',
@@ -12,6 +12,7 @@
import sys
import datetime
import time
+import math
sys.path.append('../')
from Pubnub import Pubnub
@@ -25,17 +26,19 @@
cipher_key = len(sys.argv) > 4 and sys.argv[4] or 'demo'
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com'
-#origin = '184.72.9.220'
+origin = '184.72.9.220'
## -----------------------------------------------------------------------
## Analytics
## -----------------------------------------------------------------------
analytics = {
- 'publishes' : 0, ## Total Send Requests
- 'received' : 0, ## Total Received Messages (Deliveries)
- 'successful_publishes' : 0, ## Confirmed Successful Publish Request
- 'failed_publishes' : 0, ## Confirmed UNSuccessful Publish Request
- 'failed_deliveries' : 0 ## (successful_publishes - received)
+ 'publishes' : 0, ## Total Send Requests
+ 'received' : 0, ## Total Received Messages (Deliveries)
+ 'queued' : 0, ## Total Unreceived Queue (UnDeliveries)
+ 'successful_publishes' : 0, ## Confirmed Successful Publish Request
+ 'failed_publishes' : 0, ## Confirmed UNSuccessful Publish Request
+ 'failed_deliveries' : 0, ## (successful_publishes - received)
+ 'deliverability' : 0 ## Percentage Delivery
}
trips = {
@@ -66,13 +69,20 @@ def publish_sent(info = None):
else: analytics['failed_publishes'] += 1
analytics['publishes'] += 1
- pubnub.publish({
- 'channel' : channel,
- 'callback' : publish_sent,
- 'message' : "1234567890"
- })
+ analytics['queued'] += 1
+
+ pubnub.timeout( send, 0.1 )
+
+def send():
+ if analytics['queued'] < 100:
+ pubnub.publish({
+ 'channel' : channel,
+ 'callback' : publish_sent,
+ 'message' : "1234567890"
+ })
def received(message):
+ analytics['queued'] -= 1
analytics['received'] += 1
current_trip = trips['current'] = str(datetime.datetime.now())[0:19]
last_trip = trips['last'] = str(
@@ -94,38 +104,56 @@ def received(message):
if trips[current_trip] > trips['max'] :
trips['max'] = trips[current_trip]
+def show_status():
## Update Failed Deliveries
analytics['failed_deliveries'] = \
- analytics['successful_publishes'] - analytics['received']
+ analytics['successful_publishes'] \
+ - analytics['received'] \
+ + analytics['queued'] \
+ + analytics['failed_publishes']
+
+ ## Update Deliverability
+ analytics['deliverability'] = (
+ float(analytics['received']) / \
+ float(analytics['publishes'] or 1.0)
+ ) * 100.0
+
+ """
+ if analytics['deliverability'] > 100.0:
+ analytics['deliverability'] = 100.0
+ """
## Print Display
print( (
- "%(date)s " + \
- "trip: %(total)03d " + \
- "%(date)s Trip: %(total)03d " + \
- "max:%(max)03d/sec " + \
- "avg: %(avg)03d/sec " + \
- "pubs:%(publishes)05d " + \
- "received:%(received)05d " + \
- "spub:%(successful_publishes)05d " + \
- "fpub:%(failed_publishes)05d " + \
- "failed:%(failed_deliveries)05d " + \
+ "max:%(max)03d/sec " + \
+ "avg:%(avg)03d/sec " + \
+ "pubs:%(publishes)05d " + \
+ "received:%(received)05d " + \
+ "spub:%(successful_publishes)05d " + \
+ "fpub:%(failed_publishes)05d " + \
+ "failed:%(failed_deliveries)05d " + \
+ "queued:%(queued)03d " + \
+ "delivery:%(deliverability)03f%% " + \
""
) % {
- 'date' : current_trip,
- 'total' : trips[current_trip],
'max' : trips['max'],
'avg' : trips['avg'],
'publishes' : analytics['publishes'],
'received' : analytics['received'],
'successful_publishes' : analytics['successful_publishes'],
'failed_publishes' : analytics['failed_publishes'],
'failed_deliveries' : analytics['failed_deliveries'],
- 'publishes' : analytics['publishes']
+ 'publishes' : analytics['publishes'],
+ 'deliverability' : analytics['deliverability'],
+ 'queued' : analytics['queued']
} )
+ pubnub.timeout( show_status, 1 )
-def connected(): publish_sent([1])
+def connected():
+ show_status()
+ pubnub.timeout( send, 1 )
+print( "Connected: %s\n" % origin )
pubnub.subscribe({
'channel' : channel,
'connect' : connected,
View
@@ -39,6 +39,8 @@ class Pubnub():
def start(self): reactor.run()
def stop(self): reactor.stop()
+ def timeout( self, callback, delay ):
+ reactor.callLater( delay, callback )
def __init__(
self,
@@ -252,10 +254,10 @@ def sub_callback(response):
if not response:
def time_callback(_time):
if not _time:
- reactor.callLater(time.time()+1, substabizel)
+ reactor.callLater( 1, substabizel )
return errorback("Lost Network Connection")
else:
- reactor.callLater(time.time()+1, substabizel)
+ reactor.callLater( 1, substabizel )
## ENSURE CONNECTED (Call Time Function)
return self.time({ 'callback' : time_callback })
@@ -296,7 +298,7 @@ def time_callback(_time):
str(self.subscriptions[channel]['timetoken'])
], sub_callback )
except :
- reactor.callLater(time.time()+1, substabizel)
+ reactor.callLater( 1, substabizel )
return
## BEGIN SUBSCRIPTION (LISTEN FOR MESSAGES)
@@ -12,6 +12,7 @@
import sys
import datetime
import time
+import math
sys.path.append('../')
from Pubnub import Pubnub
@@ -25,17 +26,19 @@
cipher_key = len(sys.argv) > 4 and sys.argv[4] or 'demo'
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com'
-#origin = '184.72.9.220'
+origin = '184.72.9.220'
## -----------------------------------------------------------------------
## Analytics
## -----------------------------------------------------------------------
analytics = {
- 'publishes' : 0, ## Total Send Requests
- 'received' : 0, ## Total Received Messages (Deliveries)
- 'successful_publishes' : 0, ## Confirmed Successful Publish Request
- 'failed_publishes' : 0, ## Confirmed UNSuccessful Publish Request
- 'failed_deliveries' : 0 ## (successful_publishes - received)
+ 'publishes' : 0, ## Total Send Requests
+ 'received' : 0, ## Total Received Messages (Deliveries)
+ 'queued' : 0, ## Total Unreceived Queue (UnDeliveries)
+ 'successful_publishes' : 0, ## Confirmed Successful Publish Request
+ 'failed_publishes' : 0, ## Confirmed UNSuccessful Publish Request
+ 'failed_deliveries' : 0, ## (successful_publishes - received)
+ 'deliverability' : 0 ## Percentage Delivery
}
trips = {
@@ -66,13 +69,20 @@ def publish_sent(info = None):
else: analytics['failed_publishes'] += 1
analytics['publishes'] += 1
- pubnub.publish({
- 'channel' : channel,
- 'callback' : publish_sent,
- 'message' : "1234567890"
- })
+ analytics['queued'] += 1
+
+ pubnub.timeout( send, 0.1 )
+
+def send():
+ if analytics['queued'] < 100:
+ pubnub.publish({
+ 'channel' : channel,
+ 'callback' : publish_sent,
+ 'message' : "1234567890"
+ })
def received(message):
+ analytics['queued'] -= 1
analytics['received'] += 1
current_trip = trips['current'] = str(datetime.datetime.now())[0:19]
last_trip = trips['last'] = str(
@@ -94,38 +104,56 @@ def received(message):
if trips[current_trip] > trips['max'] :
trips['max'] = trips[current_trip]
+def show_status():
## Update Failed Deliveries
analytics['failed_deliveries'] = \
- analytics['successful_publishes'] - analytics['received']
+ analytics['successful_publishes'] \
+ - analytics['received'] \
+ + analytics['queued'] \
+ + analytics['failed_publishes']
+
+ ## Update Deliverability
+ analytics['deliverability'] = (
+ float(analytics['received']) / \
+ float(analytics['publishes'] or 1.0)
+ ) * 100.0
+
+ """
+ if analytics['deliverability'] > 100.0:
+ analytics['deliverability'] = 100.0
+ """
## Print Display
print( (
- "%(date)s " + \
- "trip: %(total)03d " + \
- "%(date)s Trip: %(total)03d " + \
- "max:%(max)03d/sec " + \
- "avg: %(avg)03d/sec " + \
- "pubs:%(publishes)05d " + \
- "received:%(received)05d " + \
- "spub:%(successful_publishes)05d " + \
- "fpub:%(failed_publishes)05d " + \
- "failed:%(failed_deliveries)05d " + \
+ "max:%(max)03d/sec " + \
+ "avg:%(avg)03d/sec " + \
+ "pubs:%(publishes)05d " + \
+ "received:%(received)05d " + \
+ "spub:%(successful_publishes)05d " + \
+ "fpub:%(failed_publishes)05d " + \
+ "failed:%(failed_deliveries)05d " + \
+ "queued:%(queued)03d " + \
+ "delivery:%(deliverability)03f%% " + \
""
) % {
- 'date' : current_trip,
- 'total' : trips[current_trip],
'max' : trips['max'],
'avg' : trips['avg'],
'publishes' : analytics['publishes'],
'received' : analytics['received'],
'successful_publishes' : analytics['successful_publishes'],
'failed_publishes' : analytics['failed_publishes'],
'failed_deliveries' : analytics['failed_deliveries'],
- 'publishes' : analytics['publishes']
+ 'publishes' : analytics['publishes'],
+ 'deliverability' : analytics['deliverability'],
+ 'queued' : analytics['queued']
} )
+ pubnub.timeout( show_status, 1 )
-def connected(): publish_sent([1])
+def connected():
+ show_status()
+ pubnub.timeout( send, 1 )
+print( "Connected: %s\n" % origin )
pubnub.subscribe({
'channel' : channel,
'connect' : connected,

0 comments on commit 88ca393

Please sign in to comment.