Upping feed fetches, slowing down fetch interval for less active feeds, setting premium expire time to one year from most recent payment date (as opposed to borked payment gap logic), and adding logginf or tasking feeds.

This commit is contained in:
Samuel Clay 2013-03-28 11:16:43 -07:00
parent 15c955282b
commit e39dee98be
7 changed files with 155 additions and 19 deletions

View file

@ -210,14 +210,7 @@ class Profile(models.Model):
print " ---> %s payments" % len(payment_history)
if most_recent_payment_date:
payment_gap = 0
# If user lapsed and has no gap b/w last payment and expiration,
# they only get a full year. Otherwise, give them the gap.
if (self.premium_expire and
self.premium_expire > datetime.datetime.now() and
self.premium_expire > most_recent_payment_date):
payment_gap = (self.premium_expire - most_recent_payment_date).days
self.premium_expire = most_recent_payment_date + datetime.timedelta(days=365+payment_gap)
self.premium_expire = most_recent_payment_date + datetime.timedelta(days=365)
self.save()
def queue_new_feeds(self, new_feeds=None):

View file

@ -1219,9 +1219,9 @@ class Feed(models.Model):
# 1 update per day = 1 hours
# 10 updates = 20 minutes
updates_per_day_delay = 3 * 60 / max(.25, ((max(0, self.active_subscribers)**.2)
* (updates_per_month**0.35)))
if self.premium_subscribers > 0:
updates_per_day_delay /= min(self.active_subscribers+self.premium_subscribers, 5)
* (updates_per_month**0.15)))
if self.active_premium_subscribers > 0:
updates_per_day_delay /= min(self.active_subscribers+self.active_premium_subscribers, 4)
# Lots of subscribers = lots of updates
# 24 hours for 0 subscribers.
# 4 hours for 1 subscriber.

View file

@ -14,6 +14,7 @@ class TaskFeeds(Task):
from apps.rss_feeds.models import Feed
settings.LOG_TO_STREAM = True
now = datetime.datetime.utcnow()
start = time.time()
# Active feeds
popular_feeds = Feed.objects.filter(
@ -28,7 +29,7 @@ class TaskFeeds(Task):
next_scheduled_update__lte=now,
active=True,
active_subscribers__gte=1
).order_by('?')[:500]
).order_by('?')[:600]
active_count = feeds.count()
# Force refresh feeds
@ -71,7 +72,9 @@ class TaskFeeds(Task):
Feed.task_feeds(refresh_feeds, verbose=False)
if inactive_feeds: Feed.task_feeds(inactive_feeds, verbose=False)
if old_feeds: Feed.task_feeds(old_feeds, verbose=False)
logging.debug(" ---> ~FBTasking took %.2s seconds" % (time.time() - start))
class UpdateFeeds(Task):
name = 'update-feeds'

View file

@ -80,8 +80,15 @@ server {
alias /srv/newsblur/media/robots.txt;
}
location /munin/static/ {
alias /etc/munin/static/;
}
location /munin/ {
alias /var/cache/munin/www/;
fastcgi_split_path_info ^(/munin)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fcgi-html.sock;
include fastcgi_params;
}
location ^~ /cgi-bin/munin-cgi-graph/ {

View file

@ -27,7 +27,7 @@ NAME=spawn-fcgi-munin-graph
PID_FILE=/var/run/munin/fcgi-graph.pid
SOCK_FILE=/var/run/munin/fcgi-graph.sock
DAEMON=/usr/bin/spawn-fcgi
DAEMON_OPTS="-s $SOCK_FILE -U www-data -u www-data -g www-data /usr/lib/cgi-bin/munin-cgi-graph -P $PID_FILE"
DAEMON_OPTS="-s $SOCK_FILE -U nginx -u nginx -g www-data /usr/lib/cgi-bin/munin-cgi-graph -P $PID_FILE"
# --------------------------------------------------------------
# No edits necessary beyond this line

View file

@ -0,0 +1,119 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: spawn-fcgi-munin-html
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: starts FastCGI for Munin-Html
### END INIT INFO
# --------------------------------------------------------------
# Munin-CGI-HTML Spawn-FCGI Startscript by Julien Schmidt
# eMail: munin-trac at julienschmidt.com
# www: http://www.julienschmidt.com
# --------------------------------------------------------------
# Install:
# 1. Copy this file to /etc/init.d
# 2. Edit the variables below
# 3. run "update-rc.d spawn-fcgi-munin-html defaults"
# --------------------------------------------------------------
# Last Update: 13. November 2012
#
# Please change the following variables:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=spawn-fcgi-munin-html
PID_FILE=/var/run/munin/fcgi-html.pid
SOCK_FILE=/var/run/munin/fcgi-html.sock
DAEMON=/usr/bin/spawn-fcgi
DAEMON_OPTS="-s $SOCK_FILE -U nginx -u nginx -g www-data /usr/lib/cgi-bin/munin-cgi-html -P $PID_FILE"
# --------------------------------------------------------------
# No edits necessary beyond this line
# --------------------------------------------------------------
if [ ! -x $DAEMON ]; then
echo "File not found or is not executable: $DAEMON!"
exit 0
fi
status() {
if [ ! -r $PID_FILE ]; then
return 1
fi
FCGI_PID=`cat $PID_FILE`
if [ -z "${FCGI_PID}" ]; then
return 1
fi
FCGI_RUNNING=`ps -p ${FCGI_PID} | grep ${FCGI_PID}`
if [ -z "${FCGI_RUNNING}" ]; then
return 1
fi
return 0
}
start() {
if status; then
echo "FCGI is already running!"
exit 1
else
$DAEMON $DAEMON_OPTS
fi
}
stop () {
if ! status; then
echo "No PID-file at $PID_FILE found or PID not valid. Maybe not running"
exit 1
fi
# Kill process
kill -9 `cat $PID_FILE`
# Remove PID-file
rm -f $PID_FILE
# Remove Sock-File
rm -f $SOCK_FILE
}
case "$1" in
start)
echo "Starting $NAME: "
start
echo "... DONE"
;;
stop)
echo "Stopping $NAME: "
stop
echo "... DONE"
;;
force-reload|restart)
echo "Stopping $NAME: "
stop
echo "Starting $NAME: "
start
echo "... DONE"
;;
status)
if status; then
echo "FCGI is RUNNING"
else
echo "FCGI is NOT RUNNING"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

22
fabfile.py vendored
View file

@ -824,15 +824,29 @@ def setup_redis():
sudo('/etc/init.d/redis start')
def setup_munin():
sudo('apt-get update')
# sudo('apt-get update')
sudo('apt-get install -y munin munin-node munin-plugins-extra spawn-fcgi')
put('config/munin.conf', '/etc/munin/munin.conf', use_sudo=True)
put('config/spawn_fcgi_munin_graph.conf', '/etc/init.d/spawn_fcgi_munin_graph', use_sudo=True)
put('config/spawn_fcgi_munin_html.conf', '/etc/init.d/spawn_fcgi_munin_html', use_sudo=True)
sudo('chmod u+x /etc/init.d/spawn_fcgi_munin_graph')
sudo('/etc/init.d/spawn_fcgi_munin_graph start')
sudo('update-rc.d spawn_fcgi_munin_graph defaults')
sudo('chmod u+x /etc/init.d/spawn_fcgi_munin_html')
with settings(warn_only=True):
sudo('chown nginx.www-data munin-cgi*')
with settings(warn_only=True):
sudo('/etc/init.d/spawn_fcgi_munin_graph stop')
sudo('/etc/init.d/spawn_fcgi_munin_graph start')
sudo('update-rc.d spawn_fcgi_munin_graph defaults')
sudo('/etc/init.d/spawn_fcgi_munin_html stop')
sudo('/etc/init.d/spawn_fcgi_munin_html start')
sudo('update-rc.d spawn_fcgi_munin_html defaults')
sudo('/etc/init.d/munin-node restart')
with settings(warn_only=True):
sudo('chown nginx.www-data munin-cgi*')
with settings(warn_only=True):
sudo('/etc/init.d/spawn_fcgi_munin_graph start')
sudo('/etc/init.d/spawn_fcgi_munin_html start')
def setup_db_munin():
sudo('cp -frs %s/config/munin/mongo* /etc/munin/plugins/' % env.NEWSBLUR_PATH)