You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basics/listening-port.md
+16-5Lines changed: 16 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,11 +91,16 @@ q)\p -2000/2010 / use a free port between 2000 and 2010 in multithread
91
91
q)\p myhost:2000/2010 / use a free port between 2000 and 2010, using given hostname
92
92
```
93
93
94
-
## Multi-threaded port
94
+
## Multi-threaded input mode
95
95
96
-
A negative port sets a [multi-threaded](../kb/multithreaded-input.md) port and if used it must be the initial and only mode of operation,
96
+
A negative port sets a multi-threaded port and if used it must be the initial and only mode of operation,
97
97
i.e. do not dynamically switch between positive port and negative port.
98
98
99
+
When active, each IPC connection will create a new thread for its sole use.
100
+
Each connection uses its own heap with a minimum of 64MB, the real amount depending on the working space required by the query being executed.
101
+
[`\ts`](syscmds.md#ts-time-and-space) can be used to find the memory requirement of a query.
102
+
It is designed for serving in-memory static data to an externally constrained number of clients. It is not intended for use as a gateway, or serving mutable data.
103
+
99
104
Note that there are a number of restrictions in multithreaded mode:
100
105
101
106
* queries are unable to update globals
@@ -104,6 +109,15 @@ Note that there are a number of restrictions in multithreaded mode:
104
109
*[.z.W](../ref/dotz.md#zw-handles) has a view on main thread sockets only
105
110
* Cannot send async message
106
111
* Views can be recalculated from the main thread only
112
+
* Uncompressed pages will not be shared between threads (i.e. same situation as with starting a separate hdb for each request).
113
+
114
+
The main thread is allowed to update globals. The main thread is responsible for reading from stdin (i.e. the console) and executing any loaded scripts on start-up.
115
+
It also invokes [.z.ts](../ref/dotz.md#zts-timer) on [timer expiry](syscmds.md#t-timer).
116
+
Any connections made via IPC from the main thread, can be monitored
117
+
for callbacks (for example via an [async callback](../kb/callbacks.md)) which in turn can update globals.
118
+
While the main thread is processing an update (for example, a timer firing or console input) none of the connection threads will be processing any input.
119
+
Updates should not be frequent, as they wait for completion of exiting queries and block new queries (using multiple-read single-write lock), thus slowing processing speeds.
120
+
If an attempt is made to update globals from threads other than main, a `'no update` error is issued.
107
121
108
122
Multithreaded input mode supports WebSockets and HTTP (but not TLS) since 4.1t 2021.03.30.
109
123
TLS support available since 4.1t 2023.12.14. A custom [.z.ph](../ref/dotz.md#zph-http-get) which does not update global state should be used with HTTP.
@@ -170,6 +184,3 @@ Once you open a port in q session, it is open to all connections, including HTTP
Copy file name to clipboardExpand all lines: docs/cloud/aws/index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -284,7 +284,7 @@ The CPU requirement of the real-time database (RDB) comes from
284
284
- appending updates to local tables
285
285
- user queries
286
286
287
-
Local table updates are very efficient especially if TP sends batch updates. Nevertheless, faster CPU results in faster ingestion and lower latency. User queries are often CPU-intensive. They perform aggregation and joins, and call expensive functions. If the RDB is set up in [multithreaded input mode](../../kb/multithreaded-input.md) then user queries are executed in parallel. Furthermore, kdb+ 4.0 supports multithreading in most primitives, including `sum`, `avg`, `dev`, etc. If the RDB process is heavily used and hit by many queries, then it is recommended to start with [secondary threads](../../basics/cmdline.md#-s-secondary-threads). VMs with plenty of cores are recommended for RDB processes with large numbers of user queries.
287
+
Local table updates are very efficient especially if TP sends batch updates. Nevertheless, a faster CPU results in faster ingestion and lower latency. User queries are often CPU-intensive. They perform aggregation and joins, and call expensive functions. If the RDB is set up in [multithreaded input mode](../../basics/listening-port.md#multi-threaded-input-mode) then user queries are executed in parallel. Furthermore, kdb+ 4.0 supports multithreading in most primitives, including `sum`, `avg`, `dev`, etc. If the RDB process is heavily used and hit by many queries, then it is recommended to start with [secondary threads](../../basics/cmdline.md#-s-secondary-threads). VMs with plenty of cores are recommended for RDB processes with large numbers of user queries.
288
288
289
289
If the infrastructure is sensitive to the RDB EOD work, then powerful CPUs are recommended. Sorting tables before splaying is a CPU-intensive task.
290
290
@@ -365,7 +365,7 @@ EFA provides lower and more consistent latency and higher throughput than the TC
365
365
366
366
A network load balancer is a type of [Elastic Load Balancer](https://aws.amazon.com/elasticloadbalancing/) by Amazon. It is used for ultra-high performance, TLS offloading at scale, centralized certificate deployment, support for UDP, and static IP addresses for your application. Operating at the connection level, Network Load Balancers are capable of handling millions of requests per second securely while maintaining ultra-low latencies.
367
367
368
-
Load balancers can distribute load among applications that offer the same service. kdb+ is single-threaded by default. You can set [multithreaded input mode](../../kb/multithreaded-input.md) in which requests are processed in parallel. This however, is not recommended for gateways (due to socket usage limitation) and for q servers that process data from disk, like HDBs.
368
+
Load balancers can distribute load among applications that offer the same service. kdb+ is single-threaded by default. You can set [multithreaded input mode](../../basics/listening-port.md#multi-threaded-input-mode) in which requests are processed in parallel. This however, is not recommended for gateways (due to socket usage limitation) and for q servers that process data from disk, like HDBs.
369
369
370
370
A better approach is to use a pool of HDB processes. Distributing the queries can either be done by the gateway via async calls or by a load balancer. If the gateways are sending sync queries to the HDB load balancer, then we recommend a gateway load balancer to avoid query contention in the gateway. Furthermore, there are other tickerplant components that enjoy the benefit of load balancers to handle simultaneous requests better.
kdb+ has been multithreaded for more than 15 years, and users could leverage this explicitly through [`peach`](../ref/each.md), or via the [multithreaded input mode](../kb/multithreaded-input.md).
176
+
kdb+ has been multithreaded for more than 15 years, and users could leverage this explicitly through [`peach`](../ref/each.md), or via the [multithreaded input mode](../basics/listening-port.md#multi-threaded-input-mode).
177
177
178
178
kdb+ 4.0 adds an additional level of multithreading via primitives.
179
179
It is fully transparent to the user, requiring no code change by the user to exploit it. The underlying framework currently uses the number of threads configured as secondary threads on the command line.
0 commit comments