@deephaven-enterprise/query-utils 1.20240723.113-beta → 1.20240723.115-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,10 @@ export type ScriptDraftQuery = IDraftQuery & {
13
13
  export type IDraftQuery = EditableQueryInfo & {
14
14
  isClientSide: boolean;
15
15
  draftOwner: string;
16
+ initializationThreads?: string;
17
+ updateThreads?: string;
16
18
  };
17
- export type DraftQueryConstructorObject = Partial<IDraftQuery> & Pick<IDraftQuery, 'name' | 'owner' | 'draftOwner' | 'dbServerName'>;
19
+ export type DraftQueryConstructorObject = Partial<IDraftQuery> & Pick<IDraftQuery, 'name' | 'owner' | 'draftOwner' | 'dbServerName' | 'initializationThreads' | 'updateThreads'>;
18
20
  /**
19
21
  * A Draft Query is a client side object that contains mutable data for a Peristent Query along with some metadata.
20
22
  */
@@ -58,6 +60,8 @@ export declare class DraftQuery implements IDraftQuery {
58
60
  readonly SPARE_COUNT: "spareCount";
59
61
  readonly ASSIGNMENT_POLICY: "assignmentPolicy";
60
62
  readonly ASSIGNMENT_POLICY_PARAMS: "assignmentPolicyParams";
63
+ readonly INITIALIZATION_THREADS: "initializationThreads";
64
+ readonly UPDATE_THREADS: "updateThreads";
61
65
  }>;
62
66
  /**
63
67
  * Checks if a serial id from the server is actually a draft id
@@ -71,7 +75,7 @@ export declare class DraftQuery implements IDraftQuery {
71
75
  * @param serial a serial that contains a draft id
72
76
  */
73
77
  static serialToDraftId(serial: string): string;
74
- constructor({ isClientSide, draftOwner, serial, name, owner, type, enabled, enableGcLogs, envVars, heapSize, additionalMemory, dataMemoryRatio, jvmArgs, extraClasspaths, jvmProfile, dbServerName, scriptLanguage, scriptPath, scriptCode, scheduling, adminGroups, viewerGroups, restartUsers, timeout, workerKind, kubernetesControl, pythonControl, genericWorkerControl, typeSpecificFields, replicaCount, spareCount, assignmentPolicy, assignmentPolicyParams, }: DraftQueryConstructorObject);
78
+ constructor({ isClientSide, draftOwner, serial, name, owner, type, enabled, enableGcLogs, envVars, heapSize, additionalMemory, dataMemoryRatio, jvmArgs, extraClasspaths, jvmProfile, dbServerName, scriptLanguage, scriptPath, scriptCode, scheduling, adminGroups, viewerGroups, restartUsers, timeout, workerKind, kubernetesControl, pythonControl, genericWorkerControl, typeSpecificFields, replicaCount, spareCount, assignmentPolicy, assignmentPolicyParams, initializationThreads, updateThreads, }: DraftQueryConstructorObject);
75
79
  id: string;
76
80
  isModified: boolean;
77
81
  isClientSide: boolean;
@@ -114,6 +118,14 @@ export declare class DraftQuery implements IDraftQuery {
114
118
  spareCount: number;
115
119
  assignmentPolicy: string | null;
116
120
  assignmentPolicyParams: string | null;
121
+ /**
122
+ * initialiZationThreads and updateThreads are thread counts only used for Core workers.
123
+ * Additionally, they are not part of a Query object. These values are in Extra JVM Args.
124
+ * When a draft is created, they will be parsed and removed from JVM args.
125
+ * When the query is saved, they will be written to JVM args.
126
+ */
127
+ initializationThreads: string;
128
+ updateThreads: string;
117
129
  updateSchedule(): void;
118
130
  /**
119
131
  * Creates a deep copy of this draft query.
@@ -128,6 +140,14 @@ export declare class DraftQuery implements IDraftQuery {
128
140
  * @param editableQuery the Editable Query from the Server
129
141
  */
130
142
  saveDraftToQuery(editableQuery: Partial<EditableQueryInfo>): void;
143
+ /**
144
+ * Updates the JVM args to include the thread count for initialization and update threads.
145
+ * It is safe to call from saveDraftToQuery because the the thead counts will be set to
146
+ * system defaults for Legacy workers, which will not affect the JVM args.
147
+ * However, saving a new draft does not call saveDraftToQuery, so this method should be called
148
+ * manually in that case.
149
+ */
150
+ addThreadCountToJVMArgs(): void;
131
151
  toEditableQueryInfo(): {
132
152
  serial: string | null;
133
153
  };
@@ -3,6 +3,7 @@ import shortid from 'shortid';
3
3
  import QueryColumns from './QueryColumns';
4
4
  import QueryScheduler from './QueryScheduler';
5
5
  import { QueryType } from './QueryType';
6
+ import WorkerThreadUtils from './WorkerThreadUtils';
6
7
  const DRAFT_SERIAL_PREFIX = 'Draft ID: ';
7
8
  /**
8
9
  * A Draft Query is a client side object that contains mutable data for a Peristent Query along with some metadata.
@@ -25,7 +26,7 @@ export class DraftQuery {
25
26
  // Remove the 'Draft ID: ' marking
26
27
  return serial === null || serial === void 0 ? void 0 : serial.substring(DRAFT_SERIAL_PREFIX.length);
27
28
  }
28
- constructor({ isClientSide = false, draftOwner, serial = DraftQuery.NO_SERIAL, name, owner, type = QueryType.SCRIPT, enabled = true, enableGcLogs = true, envVars = '', heapSize = 4.0, additionalMemory = 0.0, dataMemoryRatio = 0.25, jvmArgs = '', extraClasspaths = '', jvmProfile = 'Default', dbServerName, scriptLanguage = 'Groovy', scriptPath = null, scriptCode = '', scheduling, adminGroups = [], viewerGroups = [], restartUsers = DraftQuery.RESTART_MODE.ADMIN, timeout = 0, workerKind, kubernetesControl, pythonControl, genericWorkerControl, typeSpecificFields = null, replicaCount = 1, spareCount = 0, assignmentPolicy = null, assignmentPolicyParams = null, }) {
29
+ constructor({ isClientSide = false, draftOwner, serial = DraftQuery.NO_SERIAL, name, owner, type = QueryType.SCRIPT, enabled = true, enableGcLogs = true, envVars = '', heapSize = 4.0, additionalMemory = 0.0, dataMemoryRatio = 0.25, jvmArgs = '', extraClasspaths = '', jvmProfile = 'Default', dbServerName, scriptLanguage = 'Groovy', scriptPath = null, scriptCode = '', scheduling, adminGroups = [], viewerGroups = [], restartUsers = DraftQuery.RESTART_MODE.ADMIN, timeout = 0, workerKind, kubernetesControl, pythonControl, genericWorkerControl, typeSpecificFields = null, replicaCount = 1, spareCount = 0, assignmentPolicy = null, assignmentPolicyParams = null, initializationThreads = undefined, updateThreads = undefined, }) {
29
30
  this.scheduling = [];
30
31
  // Meta Data
31
32
  this.id = shortid.generate();
@@ -45,7 +46,6 @@ export class DraftQuery {
45
46
  this.spareCount = spareCount;
46
47
  this.additionalMemory = additionalMemory;
47
48
  this.dataMemoryRatio = dataMemoryRatio;
48
- this.jvmArgs = jvmArgs;
49
49
  this.extraClasspaths = extraClasspaths;
50
50
  this.jvmProfile = jvmProfile;
51
51
  this.dbServerName = dbServerName;
@@ -64,6 +64,14 @@ export class DraftQuery {
64
64
  this.spareCount = spareCount;
65
65
  this.assignmentPolicy = assignmentPolicy;
66
66
  this.assignmentPolicyParams = assignmentPolicyParams;
67
+ // If the thread counts are not provided, they are read from the JVM args
68
+ // And they need to be removed from the JVM args
69
+ this.initializationThreads =
70
+ initializationThreads !== null && initializationThreads !== void 0 ? initializationThreads : WorkerThreadUtils.getDisplayStringFromJvmArgs(jvmArgs, WorkerThreadUtils.INITIALIZATION_THREADS_ARG);
71
+ this.updateThreads =
72
+ updateThreads !== null && updateThreads !== void 0 ? updateThreads : WorkerThreadUtils.getDisplayStringFromJvmArgs(jvmArgs, WorkerThreadUtils.UPDATE_THREADS_ARG);
73
+ // The thread count args should always be removed from the JVM args as they are stored in the DraftQuery
74
+ this.jvmArgs = WorkerThreadUtils.removeArgs(jvmArgs);
67
75
  // The scheduling array is parsed into a scheduler object
68
76
  this.scheduling = [];
69
77
  this.scheduler = new QueryScheduler(scheduling);
@@ -98,6 +106,7 @@ export class DraftQuery {
98
106
  */
99
107
  saveDraftToQuery(editableQuery) {
100
108
  var _a, _b;
109
+ this.addThreadCountToJVMArgs();
101
110
  editableQuery.name = this.name;
102
111
  editableQuery.owner = this.owner;
103
112
  editableQuery.type = this.type;
@@ -129,6 +138,17 @@ export class DraftQuery {
129
138
  editableQuery.assignmentPolicy = this.assignmentPolicy;
130
139
  editableQuery.assignmentPolicyParams = this.assignmentPolicyParams;
131
140
  }
141
+ /**
142
+ * Updates the JVM args to include the thread count for initialization and update threads.
143
+ * It is safe to call from saveDraftToQuery because the the thead counts will be set to
144
+ * system defaults for Legacy workers, which will not affect the JVM args.
145
+ * However, saving a new draft does not call saveDraftToQuery, so this method should be called
146
+ * manually in that case.
147
+ */
148
+ addThreadCountToJVMArgs() {
149
+ const { initializationThreads, updateThreads } = this;
150
+ this.jvmArgs = WorkerThreadUtils.addArgs(this.jvmArgs, initializationThreads, updateThreads);
151
+ }
132
152
  toEditableQueryInfo() {
133
153
  const editableQuery = { serial: this.serial };
134
154
  this.saveDraftToQuery(editableQuery);
@@ -204,5 +224,7 @@ DraftQuery.FIELDS = Object.freeze({
204
224
  SPARE_COUNT: 'spareCount',
205
225
  ASSIGNMENT_POLICY: `assignmentPolicy`,
206
226
  ASSIGNMENT_POLICY_PARAMS: `assignmentPolicyParams`,
227
+ INITIALIZATION_THREADS: 'initializationThreads',
228
+ UPDATE_THREADS: 'updateThreads',
207
229
  });
208
230
  export default DraftQuery;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Utility class for managing worker thread configuration arguments.
3
+ */
4
+ export declare abstract class WorkerThreadUtils {
5
+ static readonly INITIALIZATION_THREADS_ARG = "OperationInitializationThreadPool.threads";
6
+ static readonly UPDATE_THREADS_ARG = "PeriodicUpdateGraph.updateThreads";
7
+ static readonly ALL_ARGS: string[];
8
+ static readonly SYSTEM_DEFAULT_STRING = "Default";
9
+ static readonly ALL_AVAILABLE_PROCESSORS_STRING = "All available processors";
10
+ static readonly ALL_AVAILABLE_PROCESSORS_VALUE = "-1";
11
+ static readonly THREAD_ITEMS: string[];
12
+ static readonly INITIALIZATION_THREADS_HELP_TEXT = "Determines the number of threads available for parallel processing of initialization operations. Select a value or type a positive integer.";
13
+ static readonly UPDATE_THREADS_HELP_TEXT = "Determines the number of threads available for parallel processing of the Periodic Update Graph refresh cycle. Select a value or type a positive integer.";
14
+ /**
15
+ * Converts the display string to the value string.
16
+ *
17
+ * @param display the display string
18
+ * @returns the value string
19
+ */
20
+ static getValue(display: string): string;
21
+ /**
22
+ * Gets the display string for the provided JVM arguments and argument name.
23
+ *
24
+ * @param jvmArgs the JVM arguments
25
+ * @param argName the name of the argument to search for
26
+ * @returns the display string or the system default string if not found
27
+ */
28
+ static getDisplayStringFromJvmArgs(jvmArgs: string, argName: string): string;
29
+ /**
30
+ * Removes the thread count arguments from the provided jvmArgs string.
31
+ *
32
+ * @param jvmArgs the string containing JVM arguments
33
+ * @returns a new string with the thread count arguments removed
34
+ */
35
+ static removeArgs(jvmArgs: string): string;
36
+ /**
37
+ * Adds the thread count arguments to the provided jvmArgs string.
38
+ *
39
+ * @param jvmArgs the string containing JVM arguments
40
+ * @param initializationThreads the display string for the initialization threads
41
+ * @param updateThreads the display string for the update threads
42
+ * @returns the new string with the thread count arguments added
43
+ */
44
+ static addArgs(jvmArgs: string, initializationThreads: string, updateThreads: string): string;
45
+ /**
46
+ * Gets the display string for the provided value.
47
+ *
48
+ * @param value the value to convert
49
+ * @returns the display string
50
+ */
51
+ static getDisplayString(value?: string): string;
52
+ /**
53
+ * Checks if the provided value is a valid thread display string. This includes blank and partial strings, so it is not strictly validated.
54
+ *
55
+ * @param value the string to validate
56
+ * @returns true if the string is valid for display, false otherwise
57
+ */
58
+ static isValidThreadDisplayString(value: string): boolean;
59
+ /**
60
+ * Checks if the provided value is a valid thread count. This only allows positive integers or specific strings.
61
+ *
62
+ * @param value the string to validate
63
+ * @returns true if the string is a valid thread count, false otherwise
64
+ */
65
+ static isValidThreadCount(value: string): boolean;
66
+ }
67
+ export default WorkerThreadUtils;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Utility class for managing worker thread configuration arguments.
3
+ */
4
+ export class WorkerThreadUtils {
5
+ /**
6
+ * Converts the display string to the value string.
7
+ *
8
+ * @param display the display string
9
+ * @returns the value string
10
+ */
11
+ static getValue(display) {
12
+ if (display === WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_STRING) {
13
+ return WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_VALUE;
14
+ }
15
+ return display;
16
+ }
17
+ /**
18
+ * Gets the display string for the provided JVM arguments and argument name.
19
+ *
20
+ * @param jvmArgs the JVM arguments
21
+ * @param argName the name of the argument to search for
22
+ * @returns the display string or the system default string if not found
23
+ */
24
+ static getDisplayStringFromJvmArgs(jvmArgs, argName) {
25
+ const args = jvmArgs.split(/[\n\r\s]+/);
26
+ for (let i = 0; i < args.length; i += 1) {
27
+ if (args[i].includes(argName)) {
28
+ return WorkerThreadUtils.getDisplayString(args[i].split('=')[1]);
29
+ }
30
+ }
31
+ // If the value is not found, return the system default string
32
+ return WorkerThreadUtils.SYSTEM_DEFAULT_STRING;
33
+ }
34
+ /**
35
+ * Removes the thread count arguments from the provided jvmArgs string.
36
+ *
37
+ * @param jvmArgs the string containing JVM arguments
38
+ * @returns a new string with the thread count arguments removed
39
+ */
40
+ static removeArgs(jvmArgs) {
41
+ const args = jvmArgs.split(/[\n\r\s]+/);
42
+ const filteredArgs = args.filter(arg => !WorkerThreadUtils.ALL_ARGS.some(argName => arg.includes(argName)));
43
+ return filteredArgs.join(' ');
44
+ }
45
+ /**
46
+ * Adds the thread count arguments to the provided jvmArgs string.
47
+ *
48
+ * @param jvmArgs the string containing JVM arguments
49
+ * @param initializationThreads the display string for the initialization threads
50
+ * @param updateThreads the display string for the update threads
51
+ * @returns the new string with the thread count arguments added
52
+ */
53
+ static addArgs(jvmArgs, initializationThreads, updateThreads) {
54
+ // The default value means "do not set an extra JVM arg"
55
+ if (WorkerThreadUtils.isValidThreadCount(initializationThreads) &&
56
+ initializationThreads !== WorkerThreadUtils.SYSTEM_DEFAULT_STRING) {
57
+ jvmArgs += ` -D${WorkerThreadUtils.INITIALIZATION_THREADS_ARG}=${WorkerThreadUtils.getValue(initializationThreads)}`;
58
+ }
59
+ if (WorkerThreadUtils.isValidThreadCount(updateThreads) &&
60
+ updateThreads !== WorkerThreadUtils.SYSTEM_DEFAULT_STRING) {
61
+ jvmArgs += ` -D${WorkerThreadUtils.UPDATE_THREADS_ARG}=${WorkerThreadUtils.getValue(updateThreads)}`;
62
+ }
63
+ return jvmArgs.trim();
64
+ }
65
+ /**
66
+ * Gets the display string for the provided value.
67
+ *
68
+ * @param value the value to convert
69
+ * @returns the display string
70
+ */
71
+ static getDisplayString(value) {
72
+ if (value == null) {
73
+ return WorkerThreadUtils.SYSTEM_DEFAULT_STRING;
74
+ }
75
+ if (value === WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_VALUE) {
76
+ return WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_STRING;
77
+ }
78
+ if (WorkerThreadUtils.isValidThreadDisplayString(value)) {
79
+ return value;
80
+ }
81
+ return WorkerThreadUtils.SYSTEM_DEFAULT_STRING;
82
+ }
83
+ /**
84
+ * Checks if the provided value is a valid thread display string. This includes blank and partial strings, so it is not strictly validated.
85
+ *
86
+ * @param value the string to validate
87
+ * @returns true if the string is valid for display, false otherwise
88
+ */
89
+ static isValidThreadDisplayString(value) {
90
+ // Allow empty and partial strings so user can clear the input
91
+ if (value.length === 0 ||
92
+ WorkerThreadUtils.SYSTEM_DEFAULT_STRING.startsWith(value) ||
93
+ WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_STRING.startsWith(value)) {
94
+ return true;
95
+ }
96
+ return WorkerThreadUtils.isValidThreadCount(value);
97
+ }
98
+ /**
99
+ * Checks if the provided value is a valid thread count. This only allows positive integers or specific strings.
100
+ *
101
+ * @param value the string to validate
102
+ * @returns true if the string is a valid thread count, false otherwise
103
+ */
104
+ static isValidThreadCount(value) {
105
+ if (value === WorkerThreadUtils.SYSTEM_DEFAULT_STRING ||
106
+ value === WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_STRING) {
107
+ return true;
108
+ }
109
+ return Number.isInteger(Number(value)) && Number(value) >= 1;
110
+ }
111
+ }
112
+ WorkerThreadUtils.INITIALIZATION_THREADS_ARG = 'OperationInitializationThreadPool.threads';
113
+ WorkerThreadUtils.UPDATE_THREADS_ARG = 'PeriodicUpdateGraph.updateThreads';
114
+ WorkerThreadUtils.ALL_ARGS = [
115
+ WorkerThreadUtils.INITIALIZATION_THREADS_ARG,
116
+ WorkerThreadUtils.UPDATE_THREADS_ARG,
117
+ ];
118
+ WorkerThreadUtils.SYSTEM_DEFAULT_STRING = 'Default';
119
+ WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_STRING = 'All available processors';
120
+ WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_VALUE = '-1';
121
+ WorkerThreadUtils.THREAD_ITEMS = [
122
+ WorkerThreadUtils.SYSTEM_DEFAULT_STRING,
123
+ WorkerThreadUtils.ALL_AVAILABLE_PROCESSORS_STRING,
124
+ '1',
125
+ '2',
126
+ '4',
127
+ '8',
128
+ '16',
129
+ '32',
130
+ '64',
131
+ ];
132
+ WorkerThreadUtils.INITIALIZATION_THREADS_HELP_TEXT = 'Determines the number of threads available for parallel processing of initialization operations. Select a value or type a positive integer.';
133
+ WorkerThreadUtils.UPDATE_THREADS_HELP_TEXT = `Determines the number of threads available for parallel processing of the Periodic Update Graph refresh cycle. Select a value or type a positive integer.`;
134
+ export default WorkerThreadUtils;
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from './QueryColumns';
3
3
  export * from './QueryScheduler';
4
4
  export * from './QuerySchedulerValidation';
5
5
  export * from './QueryType';
6
+ export * from './WorkerThreadUtils';
package/dist/index.js CHANGED
@@ -3,3 +3,4 @@ export * from './QueryColumns';
3
3
  export * from './QueryScheduler';
4
4
  export * from './QuerySchedulerValidation';
5
5
  export * from './QueryType';
6
+ export * from './WorkerThreadUtils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven-enterprise/query-utils",
3
- "version": "1.20240723.113-beta",
3
+ "version": "1.20240723.115-beta",
4
4
  "description": "Deephaven Enterprise Query Utils",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -29,5 +29,5 @@
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
- "gitHead": "04c09a4d3c5ebdf01ad261a85388f9455726f5c6"
32
+ "gitHead": "1091fd27057aa3f9b60d89a82ffe5070490774e4"
33
33
  }