From 675de879a29b8ba0dac1494ac7810ce6e10cdf98 Mon Sep 17 00:00:00 2001 From: Thabo Date: Wed, 15 Apr 2015 15:32:39 -0700 Subject: [PATCH 1/4] fix paging on /users/tops so max page size can't be overriden --- actions/tops.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/actions/tops.js b/actions/tops.js index 673834b96..965753133 100644 --- a/actions/tops.js +++ b/actions/tops.js @@ -526,8 +526,7 @@ exports.getTopTrackMembers = { dbConnectionMap = connection.dbConnectionMap, result = {}, error, - sqlParams = {}, - isNoPaging; + sqlParams = {}; if (!dbConnectionMap) { helper.handleNoConnection(api, connection, next); return; @@ -549,8 +548,7 @@ exports.getTopTrackMembers = { } if (pageIndex === -1) { pageIndex = 1; - pageSize = MAX_INT; // No paging, show all. - isNoPaging = true; + pageSize = MAX_PAGE_SIZE; // No paging, show max allowed. } // Retrieves total number of top members for the given track. api.dataAccess.executeQuery('get_top_members_' + trackType + '_count', sqlParams, dbConnectionMap, cb); @@ -559,10 +557,9 @@ exports.getTopTrackMembers = { cb(new Error('no rows returned from get_top_members_' + trackType + '_count')); return; } - var total = rows[0].count; - result.total = total; + result.total = rows[0].count; result.pageIndex = pageIndex; - result.pageSize = isNoPaging ? total : pageSize; + result.pageSize = pageSize; result.data = []; sqlParams.firstRowIndex = (pageIndex - 1) * pageSize; sqlParams.pageSize = pageSize; From 33ff91f8293a82f9ec898217d99258dc02f145d3 Mon Sep 17 00:00:00 2001 From: Thabo Date: Thu, 16 Apr 2015 13:06:07 -0700 Subject: [PATCH 2/4] heavily cache get top tracks calls --- actions/tops.js | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/tops.js b/actions/tops.js index 965753133..993a59326 100644 --- a/actions/tops.js +++ b/actions/tops.js @@ -516,6 +516,7 @@ exports.getTopTrackMembers = { outputExample: {}, version: 'v2', transaction: 'read', + cacheLifetime: 1000 * 60 * 60 * 24, databases: ['topcoder_dw', 'tcs_dw', 'tcs_catalog'], run: function (api, connection, next) { api.log('Execute getTopTrackMembers#run', 'debug'); From cc1fdce771aad6b08aa9f5aec498fa9c178ad743 Mon Sep 17 00:00:00 2001 From: Thabo Date: Thu, 16 Apr 2015 16:50:28 -0700 Subject: [PATCH 3/4] increase node workers --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index b802bcb28..f6ff84015 100644 --- a/start.sh +++ b/start.sh @@ -3,4 +3,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # nohup node ~/tc-api/node_modules/.bin/actionHero start 2>&1 & #forever start -d -v -a -l "${DIR}/log/forever.log" "${DIR}/node_modules/actionhero/bin/actionhero" start -forever start -d -a -l "${DIR}/log/forever.log" "${DIR}/node_modules/actionhero/bin/actionhero" startCluster --workers=2 +forever start -d -a -l "${DIR}/log/forever.log" "${DIR}/node_modules/actionhero/bin/actionhero" startCluster --workers=10 From 3258c14983cc405e0c516b0fa0eb09c71a5001c7 Mon Sep 17 00:00:00 2001 From: Thabo Date: Thu, 16 Apr 2015 16:50:58 -0700 Subject: [PATCH 4/4] add better clustering commands --- workers.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/workers.sh b/workers.sh index 8c6efb03b..84ab61a43 100755 --- a/workers.sh +++ b/workers.sh @@ -2,21 +2,90 @@ ACTION=$1 SIGNAL="" +pid=$(ps ax | grep startCluster | grep -v grep | xargs | cut -f1 -d' ') +if [ "$pid" == "" ]; then + echo "No cluster master process found." + exit +fi + +function workers_ps { + ps_out=$(ps ax | grep -- "actionhero start$" | grep -v grep) + IFS=' + ' + IFS=${IFS:0:1} + workers=( $ps_out ) + } + +workers_ps + +wpids=() +for worker in "${workers[@]}" +do + wpids+=("$(echo -e "${worker}" | xargs | cut -f1 -d' ')") +done + + if [ "$ACTION" == "reload" ]; then SIGNAL="HUP" elif [ "$ACTION" == "add" ]; then SIGNAL="TTIN" elif [ "$ACTION" == "rm" ]; then SIGNAL="TTOU" -fi +elif [ "$ACTION" == "kill" ]; then + for wpid in "${wpids[@]}" + do + kill -9 $wpid # kill the workers and let master restart + done + exit +elif [ "$ACTION" == "recycle" ]; then + numWorkers=${#wpids[@]} + echo "Start Recycle, Workers Running: ${#workers[@]}" + + for wpid in "${wpids[@]}" + do + kill -TTIN $pid # add one + sleep 1 + done -if [ "$SIGNAL" == "" ]; then - echo "Usage: workers.sh [reload|add|rm]" + declare -i sleepTime + sleepTime=$numWorkers + sleep $sleepTime + + workers_ps + echo "Max Workers Running: ${#workers[@]}" + + # signal recycle of all + kill -HUP $pid + + sleepTime=$numWorkers*2 + sleep $sleepTime + + for wpid in "${wpids[@]}" + do + kill -TTOU $pid # remove one + sleep 1 + done + + sleepTime=$numWorkers/2 + sleep $sleepTime + + workers_ps + echo "End Recycle, Workers Running: ${#workers[@]}" + exit +elif [ "$ACTION" == "ls" ]; then + for worker in "${workers[@]}" + do + echo -e "${worker}" | xargs | cut -f1,4 -d' ' + done + echo "Count: ${#wpids[@]}" + exit +elif [ "$ACTION" == "count" ]; then + echo "${#wpids[@]}" + exit else - pid=$(ps ax | grep startCluster | grep -v grep | xargs | cut -f1 -d' ') - if [ "$pid" == "" ]; then echo "No cluster master process found." - else - kill -$SIGNAL $pid - echo "Signal $SIGNAL sent to process: $pid" - fi -fi \ No newline at end of file + echo "Usage: workers.sh [reload|recycle|add|rm|ls|count]" + exit +fi + +kill -$SIGNAL $pid +echo "Signal $SIGNAL sent to process: $pid"