From 70baf36e93f2be35c20e58b2d96930b70834f12a Mon Sep 17 00:00:00 2001 From: "Eric J. Korpela" Date: Wed, 28 May 2008 17:28:19 +0000 Subject: [PATCH] - Added database table credit_multiplier and script to be run daily (calculate_credit_multiplier) to determine what factor to multiply claimed credit by before insertion into the database. Changes to scheduler to implement have not yet been checked in. svn path=/trunk/boinc/; revision=15309 --- checkin_notes | 13 ++++++++++ db/schema.sql | 9 +++++++ tools/Makefile.am | 2 +- tools/calculate_credit_multiplier | 43 +++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 tools/calculate_credit_multiplier diff --git a/checkin_notes b/checkin_notes index 081dc641c1..9c85da0ddb 100644 --- a/checkin_notes +++ b/checkin_notes @@ -4450,3 +4450,16 @@ David May 28 2008 html/user/ forum_forum.php white.css + +Eric May 28 2008 + - Added database table credit_multiplier and script to be run daily + (calculate_credit_multiplier) to determine what factor to multiply claimed + credit by before insertion into the database. Changes to scheduler to + implement have not yet been checked in. + + tools/ + Makefile.am + calculate_credit_multiplier + db/ + schema.sql + diff --git a/db/schema.sql b/db/schema.sql index 67bbec6409..35859a1efd 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -581,3 +581,12 @@ create table notify ( opaque integer not null -- some other ID, e.g. that of the thread, user or PM record ); + +-- credit multiplier. Used by the assimilator and autoadjust_credit script +-- to automatically adjust granted credit. +create table credit_multiplier ( + id serial primary key, + time integer not null, + multiplier double not null default 0; +) engine=MyISAM; + diff --git a/tools/Makefile.am b/tools/Makefile.am index ae43d80f70..35748194d2 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.incl bin_PROGRAMS = create_work sign_executable dir_hier_path dir_hier_move -EXTRA_DIST = make_project xadd update_versions dbcheck_files_exist upgrade makelog.sh cleanlogs.sh vote_monitor +EXTRA_DIST = make_project xadd update_versions dbcheck_files_exist upgrade makelog.sh cleanlogs.sh vote_monitor calculate_credit_multiplier LDADD = $(LIBSCHED) $(LIBBOINC) $(RSA_LIBS) $(MYSQL_LIBS) AM_CXXFLAGS = $(MYSQL_CFLAGS) diff --git a/tools/calculate_credit_multiplier b/tools/calculate_credit_multiplier new file mode 100755 index 0000000000..4c51809730 --- /dev/null +++ b/tools/calculate_credit_multiplier @@ -0,0 +1,43 @@ +#! /bin/sh +dbhost=`grep db_host ../config.xml | tr '[\<\>]' '[ ]' | head -1 | awk '{print $2}'` +dbuser=`grep db_user ../config.xml | tr '[\<\>]' '[ ]' | head -1 | awk '{print $2}'` +dbname=`grep db_name ../config.xml | tr '[\<\>]' '[ ]' | head -1 | awk '{print $2}'` +MYSQL="mysql -D $dbname -h $dbhost -u $dbuser -N -B" + +DECAY_TIME=30*86400 + +function median_query() { + $MYSQL --execute=" + create temporary table medians (id int auto_increment primary key) + select $1 from host + where rpc_time>unix_timestamp(now())-($DECAY_TIME) + and credit_per_cpu_sec>0 + order by $1; + create temporary table ids + select round(avg(id)-0.5) as id from medians; + insert into ids select round(avg(id)+0.5) from medians; + select avg($1) from medians where id in ( + select id from ids + ); + drop table medians; + drop table ids;" +} + +median_credit_per_cpu_sec=`median_query credit_per_cpu_sec` +median_p_fpops=`median_query p_fpops` +median_p_iops=`median_query p_iops` +ratio=`$MYSQL --execute="select ($median_p_fpops+$median_p_iops)/($median_credit_per_cpu_sec)*5.787037037037e-13"` + +nrows=`$MYSQL --execute="select count(id) from credit_multiplier"` +if [ $nrows = 0 ] ; then + $MYSQL --execute="insert into credit_multiplier values (0,unix_timestamp(now())-86400,1.0)" +fi + +last_value=`$MYSQL --execute="select multiplier from credit_multiplier where (unix_timestamp(now())-time)=(select min(unix_timestamp(now())-time) from credit_multiplier)"` +last_time=`$MYSQL --execute="select unix_timestamp(now())-time from credit_multiplier where (unix_timestamp(now())-time)=(select min(unix_timestamp(now())-time) from credit_multiplier)"` + +value=`$MYSQL --execute="select ($last_value*(($DECAY_TIME)-$last_time)+$ratio*$last_time)/($DECAY_TIME)"` + +$MYSQL --execute="insert into credit_multiplier values (0,unix_timestamp(now()),$value);" + +exit 0