Skip to content

Commit

Permalink
Add possibility to control used cores
Browse files Browse the repository at this point in the history
  • Loading branch information
pverscha committed Sep 30, 2020
1 parent d0f7ada commit b89ec98
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 31 deletions.
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"node-abi": "^2.18.0",
"patch-package": "^6.2.2",
"regenerator-runtime": "^0.13.3",
"shared-memory-datastructures": "0.1.7",
"shared-memory-datastructures": "0.1.8",
"threads": "^1.4.1",
"unipept-web-components": "1.2.0-beta.1",
"unipept-web-components": "file:unipept-web-components-1.2.0.tgz",
"uuid": "^7.0.3",
"vue": "^2.6.12",
"vue-class-component": "^7.1.0",
Expand All @@ -74,7 +74,7 @@
"copy-webpack-plugin": "^5.0.4",
"css-loader": "^3.2.0",
"dotenv": "^8.2.0",
"electron": "^9.2.0",
"electron": "^10.1.2",
"electron-notarize": "^0.2.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
Expand Down
10 changes: 9 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ import ConfigurationManager from "./logic/configuration/ConfigurationManager";
import Configuration from "./logic/configuration/Configuration";
import ErrorListener from "@/logic/filesystem/ErrorListener";
const electron = require("electron");
import { Assay, ProteomicsAssay, NetworkConfiguration, AssayData } from "unipept-web-components";
import {
Assay,
ProteomicsAssay,
NetworkConfiguration,
AssayData,
QueueManager
} from "unipept-web-components";
const ipcRenderer = electron.ipcRenderer;
const BrowserWindow = electron.BrowserWindow;
Expand Down Expand Up @@ -197,6 +203,8 @@ export default class App extends Vue implements ErrorListener {
try {
let config: Configuration = await configurationManager.readConfiguration();
NetworkConfiguration.BASE_URL = config.apiSource;
NetworkConfiguration.PARALLEL_API_REQUESTS = config.maxParallelRequests;
QueueManager.initializeQueue(config.maxLongRunningTasks);
await this.$store.dispatch("setUseNativeTitlebar", config.useNativeTitlebar);
} catch (err) {
// TODO: show a proper error message to the user in case this happens
Expand Down
2 changes: 1 addition & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function createWindow() {
let options = {
width: 1200,
height: 1000,
webPreferences: { nodeIntegration: true, nodeIntegrationInWorker: true },
webPreferences: { nodeIntegration: true, nodeIntegrationInWorker: true, enableRemoteModule: true },
show: false
};

Expand Down
84 changes: 84 additions & 0 deletions src/components/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,57 @@
</v-container>
</v-card-text>
</v-card>
<h2 class="mx-auto settings-category-title">Concurrency</h2>
<v-card>
<v-card-text>
<v-container fluid>
<v-row>
<v-col cols="10">
<div class="settings-title">Long running tasks</div>
<span class="settings-text">
How many long running tasks can be computed in parallel? This setting
controls the max amount of CPU cores that can be used by this
application. Increasing this value leads to faster analysis, but
increases both memory and CPU usage of this application.
</span>
<span class="settings-text settings-important-text">
Changing this option requires you to restart the application.
</span>
</v-col>
<v-col cols="2">
<v-text-field
label="8"
single-line filled
v-model="maxLongRunningTasks"
type="number"
:rules="maxTasksRules">
</v-text-field>
</v-col>
</v-row>
<v-row>
<v-col cols="10">
<div class="settings-title">API requests</div>
<span class="settings-text">
How many API requests can be performed in parallel? This setting
controls the max amount of requests to the API server that can be
performed in parallel. Increasing this value can lead to a faster
analysis. Setting it too high could however cause stability issues on
the server side.
</span>
</v-col>
<v-col cols="2">
<v-text-field
label="5"
single-line filled
type="number"
v-model="maxParallelRequests"
:rules="maxRequestRules">
</v-text-field>
</v-col>
</v-row>
</v-container>
</v-card-text>
</v-card>
<h2 class="mx-auto settings-category-title">Appearance</h2>
<v-card>
<v-card-text>
Expand Down Expand Up @@ -91,6 +142,19 @@ export default class SettingsPage extends Vue {
Rules.url
];
private maxTasksRules: ((x: string) => boolean | string)[] = [
Rules.required,
Rules.integer,
Rules.gtZero
]
private maxRequestRules: ((x: string) => boolean | string)[] = [
Rules.required,
Rules.integer,
Rules.gtZero,
Rules.lteTen
]
private mounted() {
let configManager: ConfigurationManager = new ConfigurationManager();
configManager.readConfiguration().then((result) => this.configuration = result);
Expand All @@ -102,10 +166,29 @@ export default class SettingsPage extends Vue {
await configurationManager.writeConfiguration(this.configuration);
}
set maxLongRunningTasks(val: string) {
this.configuration.maxLongRunningTasks = Number.parseInt(val);
}
get maxLongRunningTasks(): string {
return this.configuration.maxLongRunningTasks.toString();
}
set maxParallelRequests(val: string) {
this.configuration.maxParallelRequests = Number.parseInt(val);
}
get maxParallelRequests(): string {
return this.configuration.maxParallelRequests.toString();
}
@Watch("configuration.apiSource")
@Watch("configuration.useNativeTitlebar")
@Watch("configuration.maxLongRunningTasks")
@Watch("configuration.maxParallelRequests")
private async saveChanges(): Promise<void> {
NetworkConfiguration.BASE_URL = this.configuration.apiSource;
NetworkConfiguration.PARALLEL_API_REQUESTS = this.configuration.maxParallelRequests;
this.updateStore("setUseNativeTitlebar", this.configuration.useNativeTitlebar);
}
Expand Down Expand Up @@ -144,6 +227,7 @@ export default class SettingsPage extends Vue {
.settings-important-text {
font-style: italic;
font-weight: bold;
display: block;
}
.settings-category-title:not(:first-child) {
Expand Down
14 changes: 13 additions & 1 deletion src/components/validation/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Rules {

/**
* The field content must be longer than a predefinied value.
*
*
* @param length The minimum length of the field's content.
*/
public static minLength(length: number): (x: string) => boolean | string {
Expand All @@ -33,4 +33,16 @@ export default class Rules {
"(\\#[-a-z\\d_]*)?$","i"); // fragment locator
return pattern.test(x) || "An invalid URL is provided.";
}

public static integer: (x: string) => boolean | string = (x: string) => {
return Number.isInteger(Number.parseFloat(x)) || "Provided value is not a valid integer.";
}

public static gtZero: (x: string) => boolean | string = (x: string) => {
return Number.parseInt(x) > 0 || "Provided value must be larger than zero.";
}

public static lteTen: (x: string) => boolean | string = (x: string) => {
return Number.parseInt(x) <= 10 || "Provided value must be 10 or smaller.";
}
}
2 changes: 2 additions & 0 deletions src/logic/configuration/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default interface Configuration {
apiSource: string;
useNativeTitlebar: boolean;
maxLongRunningTasks: number;
maxParallelRequests: number;
}
12 changes: 10 additions & 2 deletions src/logic/configuration/ConfigurationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ export default class ConfigurationManager {
// values.
private static readonly DEFAULT_CONFIG: Configuration = {
apiSource: "https://unipept.ugent.be",
useNativeTitlebar: false
useNativeTitlebar: false,
maxLongRunningTasks: 8,
maxParallelRequests: 5
};
// Reference to the last configuration that was returned by this manager. Can be used to update the current
// configuration and write the changes to disk (without having to read it again).
private static currentConfiguration: Configuration = null;

// Contains a function for every field of a Configuration object that checks whether it's valid or not.
private configurationRequirements: ((x: Configuration) => boolean)[] = [
(config: Configuration) => this.isUrl(config.apiSource)
(config: Configuration) => this.isUrl(config.apiSource),
(config: Configuration) => Number.isInteger(config.maxLongRunningTasks) && config.maxLongRunningTasks >= 1,
(config: Configuration) => {
return Number.isInteger(config.maxParallelRequests) &&
config.maxParallelRequests <= 10 &&
config.maxParallelRequests >= 1
}
]

private app: App;
Expand Down

0 comments on commit b89ec98

Please sign in to comment.