From a38958ab7b808a7d5c4c1b45cf449c4c9b8b4eb9 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 17 Jun 2021 11:21:37 +0100 Subject: [PATCH] Tools: Added scripts to test server performances --- packages/app-cli/tests/.gitignore | 3 +- .../support/serverPerformances/testPerf.sh | 55 +++++++++++++++++++ packages/lib/Synchronizer.ts | 5 +- packages/server/package.json | 3 + packages/server/src/app.ts | 5 ++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100755 packages/app-cli/tests/support/serverPerformances/testPerf.sh diff --git a/packages/app-cli/tests/.gitignore b/packages/app-cli/tests/.gitignore index 0991d4e81..9e516568d 100644 --- a/packages/app-cli/tests/.gitignore +++ b/packages/app-cli/tests/.gitignore @@ -1,2 +1,3 @@ test data/ -export/ \ No newline at end of file +export/ +support/serverPerformances/testPerfCommands.txt \ No newline at end of file diff --git a/packages/app-cli/tests/support/serverPerformances/testPerf.sh b/packages/app-cli/tests/support/serverPerformances/testPerf.sh new file mode 100755 index 000000000..0b94bfc07 --- /dev/null +++ b/packages/app-cli/tests/support/serverPerformances/testPerf.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +ROOT_DIR="$SCRIPT_DIR/../../../../.." + +COMMANDS=($(echo $1 | tr "," "\n")) +PROFILE_DIR=~/.config/joplindev-testperf + +CMD_FILE="$SCRIPT_DIR/testPerfCommands.txt" +rm -f "$CMD_FILE" +touch "$CMD_FILE" + +for CMD in "${COMMANDS[@]}" +do + if [[ $CMD == "createUsers" ]]; then + + curl --data '{"action": "createTestUsers"}' -H 'Content-Type: application/json' http://api.joplincloud.local:22300/api/debug + + # elif [[ $CMD == "createData" ]]; then + + # echo 'mkbook "shared"' >> "$CMD_FILE" + # echo 'mkbook "other"' >> "$CMD_FILE" + # echo 'use "shared"' >> "$CMD_FILE" + # echo 'mknote "note 1"' >> "$CMD_FILE" + # echo 'mknote "note 2"' >> "$CMD_FILE" + + elif [[ $CMD == "reset" ]]; then + + USER_EMAIL="user1@example.com" + rm -rf "$PROFILE_DIR" + echo "config keychain.supported 0" >> "$CMD_FILE" + echo "config sync.target 9" >> "$CMD_FILE" + echo "config sync.9.path http://api.joplincloud.local:22300" >> "$CMD_FILE" + echo "config sync.9.username $USER_EMAIL" >> "$CMD_FILE" + echo "config sync.9.password 123456" >> "$CMD_FILE" + + # elif [[ $CMD == "e2ee" ]]; then + + # echo "e2ee enable --password 111111" >> "$CMD_FILE" + + else + + echo "Unknown command: $CMD" + exit 1 + + fi +done + +cd "$ROOT_DIR/packages/app-cli" +npm start -- --profile "$PROFILE_DIR" batch "$CMD_FILE" +npm start -- --profile "$PROFILE_DIR" import ~/Desktop/Joplin_17_06_2021.jex +npm start -- --profile "$PROFILE_DIR" sync + diff --git a/packages/lib/Synchronizer.ts b/packages/lib/Synchronizer.ts index 89263e73d..53d328c25 100644 --- a/packages/lib/Synchronizer.ts +++ b/packages/lib/Synchronizer.ts @@ -169,7 +169,7 @@ export default class Synchronizer { if (report.deleteRemote) lines.push(_('Deleted remote items: %d.', report.deleteRemote)); if (report.fetchingTotal && report.fetchingProcessed) lines.push(_('Fetched items: %d/%d.', report.fetchingProcessed, report.fetchingTotal)); if (report.cancelling && !report.completedTime) lines.push(_('Cancelling...')); - if (report.completedTime) lines.push(_('Completed: %s', time.formatMsToLocal(report.completedTime))); + if (report.completedTime) lines.push(_('Completed: %s (%s)', time.formatMsToLocal(report.completedTime), `${Math.round((report.completedTime - report.startTime) / 1000)}s`)); if (this.reportHasErrors(report)) lines.push(_('Last error: %s', report.errors[report.errors.length - 1].toString().substr(0, 500))); return lines; @@ -225,6 +225,7 @@ export default class Synchronizer { if (n == 'starting') continue; if (n == 'finished') continue; if (n == 'state') continue; + if (n == 'startTime') continue; if (n == 'completedTime') continue; this.logger().info(`${n}: ${report[n] ? report[n] : '-'}`); } @@ -356,6 +357,8 @@ export default class Synchronizer { const outputContext = Object.assign({}, lastContext); + this.progressReport_.startTime = time.unixMs(); + this.dispatch({ type: 'SYNC_STARTED' }); eventManager.emit('syncStart'); diff --git a/packages/server/package.json b/packages/server/package.json index 0678404b3..613324d6d 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -4,6 +4,9 @@ "private": true, "scripts": { "start-dev": "nodemon --config nodemon.json --ext ts,js,mustache,css,tsx dist/app.js --env dev", + "devCreateDb": "node dist/app.js --env dev --create-db", + "devDropTables": "node dist/app.js --env dev --drop-tables", + "devDropDb": "node dist/app.js --env dev --drop-db", "start": "node dist/app.js", "generateTypes": "rm -f db-buildTypes.sqlite && npm run start -- --migrate-db --env buildTypes && node dist/tools/generateTypes.js && mv db-buildTypes.sqlite schema.sqlite", "tsc": "tsc --project tsconfig.json", diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index 3e6180d1f..a822e8924 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -27,6 +27,11 @@ const env: Env = argv.env as Env || Env.Prod; const defaultEnvVariables: Record = { dev: { + // To test with the Postgres database, uncomment DB_CLIENT below and + // comment out SQLITE_DATABASE. Then start the Postgres server using + // `docker-compose --file docker-compose.db-dev.yml up` + + // DB_CLIENT: 'pg', SQLITE_DATABASE: `${sqliteDefaultDir}/db-dev.sqlite`, }, buildTypes: {