Skip to content

Commit bab1a2b

Browse files
Merge pull request #325 from sshanks-kx/refactor
refactor
2 parents 61de8b9 + 4d81c71 commit bab1a2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1192
-1594
lines changed

docs/architecture/index.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ KX’s [Fusion interfaces](../interfaces/index.md#fusion-interfaces) connect kdb
2929

3030
### Tickerplant (TP)
3131

32-
A kdb+ processing acting as a TP (tickerplant) captures the initial data feed, writes it to the log file and [publishes](../kb/publish-subscribe.md) these messages to any registered subscribers.
32+
A kdb+ processing acting as a TP (tickerplant) captures the initial data feed, writes it to the log file and publishes these messages to any registered subscribers.
3333
Aims for zero-latency.
3434
Includes ingesting data in batch mode.
3535

3636
Manages subscriptions: adds and removes subscribers, and sends subscriber table definitions.
3737

3838
Handles end-of-day (EOD) processing.
3939

40+
[`tick.q`](tickq.md) represents a tickerplant and is provided as a starting point for most environments.
41+
4042
!!! tip "Best practices for tickerplants"
4143

4244
Tickerplants should be lightweight, not capturing data and using very little memory.
@@ -67,6 +69,8 @@ At startup, the RDB sends a message to the tickerplant and receives a reply cont
6769

6870
At end of day usually writes intraday data to the Historical Database, and sends it a new EOD message.
6971

72+
[`r.q`](rq.md) represents a tickerplant and is provided as a starting point for most environments.
73+
7074
!!! tip "Best practices for real-time databases"
7175

7276
RDBs queried intraday should exploit attributes in their tables. For example, a trade table might be marked as sorted by time (`` `s#time``) and grouped by sym (`` `g#sym``).
@@ -157,26 +161,3 @@ Can connect both the real-time and historical data to allow users to query acros
157161
[Query Routing: A kdb+ framework for a scalable, load balanced system](../wp/query-routing/index.md)
158162

159163

160-
## :fontawesome-solid-hand-point-right: What next?
161-
162-
:fontawesome-regular-map:
163-
[Building real-time tick subscribers](../wp/rt-tick/index.md)
164-
<br>
165-
:fontawesome-regular-map:
166-
[Data recovery for kdb+ tick](../wp/data-recovery.md)
167-
<br>
168-
:fontawesome-regular-map:
169-
[Disaster-recovery planning for kdb+ tick systems](../wp/disaster-recovery/index.md)
170-
<br>
171-
:fontawesome-regular-map:
172-
[Intraday writedown solutions](../wp/intraday-writedown/index.md)
173-
<br>
174-
:fontawesome-regular-map:
175-
[Query routing: a kdb+ framework for a scalable load-balanced system](../wp/query-routing/index.md)
176-
<br>
177-
:fontawesome-regular-map:
178-
[Order book: a kdb+ intraday storage and access methodology](../wp/order-book.md)
179-
<br>
180-
:fontawesome-regular-map:
181-
[kdb+tick profiling for throughput optimization](../wp/tick-profiling.md)
182-

docs/architecture/rq.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: RBB (r.q) | Documentation for q and kdb+
3+
description: How to construct an RDB
4+
keywords: kdb+, q, rdb, streaming
5+
---
6+
# Real-time Database (RDB) using r.q
7+
8+
`r.q` is available from :fontawesome-brands-github:[KxSystems/kdb-tick](https://github.com/KxSystems/kdb-tick)
9+
10+
## Overview
11+
12+
A kdb+ process acting as an RDB stores a current day’s data in-memory for client queries.
13+
It can write its contents to disk at end-of-day, clearing out it in-memory data to prepare for the next day.
14+
After writing data to disk, it instructs a HDB to load the written data.
15+
16+
### Customization
17+
18+
`r.q` provides a starting point to most environments. The source code is freely avaialble and can be tailered to individual needs. For example:
19+
20+
#### Memory use
21+
22+
The default RDB stores all of a days data in memory before end-of-day writing to disk. The host machines should be configured that all required resources
23+
can handle the demands that may be made of them (both for today and the future).
24+
Depending on when there may be periods of low/no activity, [garbage collection](../ref/dotq.md#gc-garbage-collect) could be deployed after clearing tables at end-of-day, or a system for intra-day writedowns.
25+
26+
#### User queries
27+
28+
A gateway process should control user queries and authorization/authentication, using RDBs/RTEs/HDBs to retrieve the required information.
29+
If known/common queries can be designed, the RDB can load additional scripts to pre-define functions a gateway can call.
30+
31+
### End-of-day
32+
33+
The end-of-day event is governed by the tickerplant process. The tickerplant calls the RDB [`.u.end`](#uend) function when this event occurs.
34+
The main end-of-day event for an RDB is to save todays data from memory to disk, clear its tables and cause the HDB to be aware of a new days dataset for it to access.
35+
36+
!!! Note "[.u.rep](#urep) sets the HDB directory be the same as the tickerplant log file directory. This can be edited to use a different directory if required"
37+
38+
### Recovery
39+
40+
Using IPC, the RDB process can retrieve the current tickerplant log location and use via the [variables](tickq.md#variables) the tickerplant maintains.
41+
The function [`.u.rep`](#urep) is then used to populate any tables from the log.
42+
43+
!!! Note "The RDB should be able to access the tickerplant log from a directory on the same machine. The RDB/tickerplant can be changed to reside on different hosts but this increases the resources needed to transmit the log file contents over the network."
44+
45+
## Usage
46+
47+
```bash
48+
q tick/r.q [host1]:port1[:usr:pwd] [host2]:port2[:usr:pwd] [-p 5020]
49+
```
50+
51+
| Parameter Name | Description | Default |
52+
| ---- | ---- | --- |
53+
| host1 | host running kdb+ instance that the RDB will subscribe to e.g. tickerplant host | localhost |
54+
| port1 | port of kdb+ instance that the RDB will subscribe to e.g. tickerplant port | 5010 |
55+
| host2 | host of kdb+ instance to inform at end-of-day, after data saved to disk e.g. HBD host | localhost |
56+
| port2 | port of kdb+ instance to inform at end-of-day, after data saved to disk e.g. HBD port | 5012 |
57+
| usr | username | &lt;none&gt; |
58+
| pwd | password | &lt;none&gt; |
59+
| -p | [listening port](../basics/cmdline.md#-p-listening-port) for client communications | &lt;none&gt; |
60+
61+
!!! Note "Standard kdb+ [command line options](../basics/cmdline.md) may also be passed"
62+
63+
## Variables
64+
65+
| Name | Description |
66+
| ---- | ---- |
67+
| .u.x | Connection list. First element populated by [`host1`](#usage) (tickerplant), and second element populated by [`host2`](#usage) (HDB) |
68+
69+
## Functions
70+
71+
Functions are open source & open to customisation.
72+
73+
### upd
74+
75+
Called by external process to update table data. Defaults to [`insert`](../ref/insert.md) to insert/append data to a table.
76+
77+
```q
78+
upd[x;y]
79+
```
80+
Where
81+
82+
* `x` is a symbol atom naming a table
83+
* `y` is table data to add to table `x`, which can contain one or more rows.
84+
85+
### .u.end
86+
87+
Perform end-of-day actions of saving tables to disk, clearing tables and running reload on HDB instance to make it aware of new day of data.
88+
89+
```q
90+
.u.end[x]
91+
```
92+
Where x is the date that has ended.
93+
94+
Actions performed:
95+
96+
* finds all tables with the group attribute on the sym column
97+
* calls [`.Q.dpft`](../ref/dotq.md#hdpf-save-tables), with params:
98+
* HDB connection from [`.u.x`](#variables) (second element)
99+
* current directory (note: directory was changed in [`.u.rep`](#urep))
100+
* date passed to this function (`x`) i.e. day that is ending
101+
* `` `sym `` column
102+
* re-apply group attribute to sym column for those tables found in first steps (as clearing the table removed grouped attribute)
103+
104+
### .u.rep
105+
106+
Initialise RDB by creating tables, which is then populated with any existing tickerplant log. Will set the HDB directory to use at end-of-day.
107+
108+
```q
109+
.u.rep[x;y]
110+
```
111+
Where
112+
113+
* `x` is a list of table details, each element a two item list
114+
* symbol for table name
115+
* schema table
116+
* `y` is the tickerplant log details.log comprising of a two item list:
117+
* a long for the log count (null represents no log)
118+
* a file symbol for the location of the current tickerplant log (null represents no log)
119+
120+
Actions performed:
121+
122+
* tables are created using `x`
123+
* if a tickerplant log file has been provided
124+
* log file is replayed using [`-11!`](../basics/internal.md#-11-streaming-execute) to populate tables
125+
* set the HDB directory by changing the working directory to the same directory as used by the log file (see [`tick.q`](tickq.md#usage) for details on how to alter the log file directory).
126+

0 commit comments

Comments
 (0)