Skip to content

Commit e5e22b4

Browse files
authored
Merge pull request #377 from sshanks-kx/mtim
2 pages were discussing same thing in different ways
2 parents 620d703 + 4963cdb commit e5e22b4

File tree

8 files changed

+22
-34
lines changed

8 files changed

+22
-34
lines changed

docs/basics/cmdline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ See
243243
[`\p` system command](syscmds.md#p-listening-port)
244244
<br>
245245
:fontawesome-solid-graduation-cap:
246-
[Multithreaded input mode](../kb/multithreaded-input.md),
246+
[Multithreaded input mode](listening-port.md#multi-threaded-input-mode),
247247
[Changes in 3.5](../releases/ChangesIn3.5.md#socket-sharding)
248248
<br>
249249
:fontawesome-regular-map:

docs/basics/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ close
9898
[](){#con}
9999
con
100100

101-
: qcon client is not supported when kdb+ is in [multithreaded input mode](../kb/multithreaded-input.md)
101+
: qcon client is not supported when kdb+ is in [multithreaded input mode](listening-port.md#multi-threaded-input-mode)
102102

103103
[](){#cond}
104104
cond

docs/basics/listening-port.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ q)\p -2000/2010 / use a free port between 2000 and 2010 in multithread
9191
q)\p myhost:2000/2010 / use a free port between 2000 and 2010, using given hostname
9292
```
9393

94-
## Multi-threaded port
94+
## Multi-threaded input mode
9595

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,
9797
i.e. do not dynamically switch between positive port and negative port.
9898

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+
99104
Note that there are a number of restrictions in multithreaded mode:
100105

101106
* queries are unable to update globals
@@ -104,6 +109,15 @@ Note that there are a number of restrictions in multithreaded mode:
104109
* [.z.W](../ref/dotz.md#zw-handles) has a view on main thread sockets only
105110
* Cannot send async message
106111
* 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.
107121

108122
Multithreaded input mode supports WebSockets and HTTP (but not TLS) since 4.1t 2021.03.30.
109123
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
170184
Command-line options [`-e`](cmdline.md#-e-tls-server-mode),
171185
[`-p`](cmdline.md#-p-listening-port);
172186
system command [`\p`](syscmds.md#p-listening-port)
173-
<br>
174-
:fontawesome-solid-graduation-cap:
175-
[Multithreaded input mode](../kb/multithreaded-input.md)

docs/basics/syscmds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ See
525525
[`-p` command-line option ](cmdline.md#-p-listening-port)
526526
<br>
527527
:fontawesome-solid-graduation-cap:
528-
[Multithreaded input mode](../kb/multithreaded-input.md),
528+
[Multithreaded input mode](listening-port.md#multi-threaded-input-mode),
529529
[Changes in 3.5](../releases/ChangesIn3.5.md#socket-sharding)
530530
<br>
531531
:fontawesome-regular-map:

docs/cloud/aws/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ The CPU requirement of the real-time database (RDB) comes from
284284
- appending updates to local tables
285285
- user queries
286286

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.
288288

289289
If the infrastructure is sensitive to the RDB EOD work, then powerful CPUs are recommended. Sorting tables before splaying is a CPU-intensive task.
290290

@@ -365,7 +365,7 @@ EFA provides lower and more consistent latency and higher throughput than the TC
365365

366366
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.
367367

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.
369369

370370
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.
371371

docs/kb/multithreaded-input.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/releases/ChangesIn4.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ h(reval(value;)enlist@;(key;`$":/home/charlie/db"))
173173

174174
## :fontawesome-solid-bolt: Multithreaded primitives
175175

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](../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).
177177

178178
kdb+ 4.0 adds an additional level of multithreading via primitives.
179179
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.

mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ nav:
474474
- Coding:
475475
- Geospatial indexing: kb/geospatial.md
476476
- Linear programming: kb/lp.md
477-
- Multithreaded input: kb/multithreaded-input.md
478477
- Multithreaded primitives: kb/mt-primitives.md
479478
- Pivoting tables: kb/pivoting-tables.md
480479
- Precision: basics/precision.md

0 commit comments

Comments
 (0)