Skip to content

Commit

Permalink
throttling: fix queue to init instantly unless throttle, instead of w…
Browse files Browse the repository at this point in the history
…aiting for in-order ping, reduces queuing unless

at max or throttled by init speed, lower wait ping timeout
nginx: set works to 8
uwsgi: use gevent again
  • Loading branch information
ikreymer committed Dec 2, 2015
1 parent c33c4bc commit cbd73cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ throttle_max_avg: 0.60
throttle_samples: 10
throttle_expire_secs: 60

queue_expire_secs: 30
queue_expire_secs: 10
remove_expired_secs: 20

image_prefix: netcapsule
Expand Down
16 changes: 10 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ def am_i_next(self, enc_id):
if not client_id:
enc_id, client_id = dc.add_new_client()

if not self.throttle():
self.redis.incr('next_client')
return enc_id, -1

client_id = int(client_id)
next_client = int(self.redis.get('next_client'))

# not next client
if next_client != client_id:
if client_id > next_client:
# if this client expired, delete it from queue
if not self.redis.get('q:' + str(next_client)):
print('skipping expired', next_client)
Expand All @@ -198,12 +202,12 @@ def am_i_next(self, enc_id):
return enc_id, client_id - next_client

# if true, container not avail yet
if self.throttle():
self.redis.expire('q:' + str(client_id), self.Q_EXPIRE_TIME)
return enc_id, client_id - next_client
#if self.throttle():
self.redis.expire('q:' + str(client_id), self.Q_EXPIRE_TIME)
return enc_id, client_id - next_client

self.redis.incr('next_client')
return enc_id, -1
#self.redis.incr('next_client')
#return enc_id, -1

def throttle(self):
num_containers = self.redis.hlen('all_containers')
Expand Down
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user www-data;
worker_processes 4;
worker_processes 8;
pid /run/nginx.pid;

events {
Expand Down
6 changes: 3 additions & 3 deletions pywb/uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ venv = $(VIRTUAL_ENV)
endif =

processes = 20
threads = 20
#gevent = 100
#gevent-early-monkey-patch =
#threads = 20
gevent = 100
gevent-early-monkey-patch =

cache2 = name=sesh,items=500,blocksize=64,keysize=64

Expand Down

0 comments on commit cbd73cc

Please sign in to comment.