Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
820aae2
add month infinity
sshanks-kx Jul 22, 2024
6e8fd03
amend at examples
sshanks-kx Jul 22, 2024
5a80cb1
improved details of .Q.hdpf
sshanks-kx Jul 22, 2024
eaa0a89
add link for deferred sync
sshanks-kx Jul 24, 2024
1d95cd2
add tick details
sshanks-kx Jul 24, 2024
873bf8a
fix format
sshanks-kx Jul 24, 2024
6c5954e
tidy up
sshanks-kx Jul 24, 2024
5d53162
reduce file - dup source code, link to relevant info
sshanks-kx Jul 24, 2024
5c792ed
add clarity, remove dups
sshanks-kx Jul 25, 2024
e3a88f8
rename and add links
sshanks-kx Jul 26, 2024
a2ea115
fix links
sshanks-kx Jul 26, 2024
d9124a5
publish-subscribe page now covered by u.q
sshanks-kx Jul 26, 2024
c610947
add details of multithreaded primatives
sshanks-kx Jul 28, 2024
772992b
add details of multithreaded primative
sshanks-kx Jul 28, 2024
f4a2bc8
add multithread primative details
sshanks-kx Jul 28, 2024
377551a
add multithreaded primitive details
sshanks-kx Jul 28, 2024
2203600
tickerplant/rdb intro
sshanks-kx Jul 28, 2024
73da1d3
add multithread primitive details
sshanks-kx Jul 29, 2024
01913f6
updated matlab for newer versions & fixed example
sshanks-kx Jul 29, 2024
08f3c34
added link to multithreaded primitives
sshanks-kx Jul 30, 2024
af07e6a
referencing old forum no longer used
sshanks-kx Jul 31, 2024
298aee7
reference scripts used directly in learning
sshanks-kx Jul 31, 2024
71f091e
add links, format code
sshanks-kx Jul 31, 2024
59592b7
script ref were used, rather than on seperate page
sshanks-kx Jul 31, 2024
2631977
vwap example didnt work - fixed
sshanks-kx Jul 31, 2024
8ba1c07
bug in as-of-quote example
sshanks-kx Jul 31, 2024
29358b2
prevent some erroneous output for example script
sshanks-kx Jul 31, 2024
722253f
add matlab null details
sshanks-kx Aug 1, 2024
76042ed
put example code into 1 section rather than split
sshanks-kx Aug 1, 2024
f765ce2
fix typo in ssl
sshanks-kx Aug 1, 2024
266aef7
fixed incorrect calc for num blocks
sshanks-kx Aug 2, 2024
3226674
fix details on ssl thread for c api
sshanks-kx Aug 2, 2024
c98d30c
Update docs/architecture/rq.md
sshanks-kx Aug 2, 2024
a8cdf53
Update docs/architecture/rq.md
sshanks-kx Aug 2, 2024
fadf500
Update docs/architecture/rq.md
sshanks-kx Aug 2, 2024
db30bce
Update docs/architecture/rq.md
sshanks-kx Aug 2, 2024
778290a
Update docs/wp/data-recovery.md
sshanks-kx Aug 2, 2024
26b6215
Update docs/wp/data-recovery.md
sshanks-kx Aug 2, 2024
84eaa91
Update docs/wp/data-recovery.md
sshanks-kx Aug 2, 2024
a0e79c5
Update docs/architecture/tickq.md
sshanks-kx Aug 2, 2024
48ae818
Update docs/architecture/rq.md
sshanks-kx Aug 2, 2024
45fcb4c
Update docs/wp/capi/index.md
sshanks-kx Aug 2, 2024
fba5958
Update docs/architecture/tickq.md
sshanks-kx Aug 2, 2024
9d7abb6
Update docs/architecture/tickq.md
sshanks-kx Aug 2, 2024
da357a6
Update docs/wp/data-recovery.md
sshanks-kx Aug 2, 2024
97c6c3f
Update docs/architecture/tickq.md
sshanks-kx Aug 2, 2024
2448c7e
Update docs/architecture/tickq.md
sshanks-kx Aug 2, 2024
8b23bc5
Update docs/architecture/tickq.md
sshanks-kx Aug 2, 2024
e599d1f
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
82175a6
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
21cd945
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
3b5f60d
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
9653dba
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
a5fef08
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
996aef3
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
6c2d359
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
fa3f3fc
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
9586ea7
Update docs/architecture/uq.md
sshanks-kx Aug 2, 2024
a156a59
Update docs/learn/startingkdb/hdb.md
sshanks-kx Aug 2, 2024
b71372e
Update docs/learn/startingkdb/hdb.md
sshanks-kx Aug 2, 2024
4d81c71
Update docs/ref/aj.md
sshanks-kx Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions docs/architecture/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ KX’s [Fusion interfaces](../interfaces/index.md#fusion-interfaces) connect kdb

### Tickerplant (TP)

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.
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.
Aims for zero-latency.
Includes ingesting data in batch mode.

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

Handles end-of-day (EOD) processing.

[`tick.q`](tickq.md) represents a tickerplant and is provided as a starting point for most environments.

!!! tip "Best practices for tickerplants"

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

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

[`r.q`](rq.md) represents a tickerplant and is provided as a starting point for most environments.

!!! tip "Best practices for real-time databases"

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``).
Expand Down Expand Up @@ -157,26 +161,3 @@ Can connect both the real-time and historical data to allow users to query acros
[Query Routing: A kdb+ framework for a scalable, load balanced system](../wp/query-routing/index.md)


## :fontawesome-solid-hand-point-right: What next?

:fontawesome-regular-map:
[Building real-time tick subscribers](../wp/rt-tick/index.md)
<br>
:fontawesome-regular-map:
[Data recovery for kdb+ tick](../wp/data-recovery.md)
<br>
:fontawesome-regular-map:
[Disaster-recovery planning for kdb+ tick systems](../wp/disaster-recovery/index.md)
<br>
:fontawesome-regular-map:
[Intraday writedown solutions](../wp/intraday-writedown/index.md)
<br>
:fontawesome-regular-map:
[Query routing: a kdb+ framework for a scalable load-balanced system](../wp/query-routing/index.md)
<br>
:fontawesome-regular-map:
[Order book: a kdb+ intraday storage and access methodology](../wp/order-book.md)
<br>
:fontawesome-regular-map:
[kdb+tick profiling for throughput optimization](../wp/tick-profiling.md)

126 changes: 126 additions & 0 deletions docs/architecture/rq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: RBB (r.q) | Documentation for q and kdb+
description: How to construct an RDB
keywords: kdb+, q, rdb, streaming
---
# Real-time Database (RDB) using r.q

`r.q` is available from :fontawesome-brands-github:[KxSystems/kdb-tick](https://github.com/KxSystems/kdb-tick)

## Overview

A kdb+ process acting as an RDB stores a current day’s data in-memory for client queries.
It can write its contents to disk at end-of-day, clearing out it in-memory data to prepare for the next day.
After writing data to disk, it instructs a HDB to load the written data.

### Customization

`r.q` provides a starting point to most environments. The source code is freely avaialble and can be tailered to individual needs. For example:

#### Memory use

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
can handle the demands that may be made of them (both for today and the future).
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.

#### User queries

A gateway process should control user queries and authorization/authentication, using RDBs/RTEs/HDBs to retrieve the required information.
If known/common queries can be designed, the RDB can load additional scripts to pre-define functions a gateway can call.

### End-of-day

The end-of-day event is governed by the tickerplant process. The tickerplant calls the RDB [`.u.end`](#uend) function when this event occurs.
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.

!!! 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"

### Recovery

Using IPC, the RDB process can retrieve the current tickerplant log location and use via the [variables](tickq.md#variables) the tickerplant maintains.
The function [`.u.rep`](#urep) is then used to populate any tables from the log.

!!! 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."

## Usage

```bash
q tick/r.q [host1]:port1[:usr:pwd] [host2]:port2[:usr:pwd] [-p 5020]
```

| Parameter Name | Description | Default |
| ---- | ---- | --- |
| host1 | host running kdb+ instance that the RDB will subscribe to e.g. tickerplant host | localhost |
| port1 | port of kdb+ instance that the RDB will subscribe to e.g. tickerplant port | 5010 |
| host2 | host of kdb+ instance to inform at end-of-day, after data saved to disk e.g. HBD host | localhost |
| port2 | port of kdb+ instance to inform at end-of-day, after data saved to disk e.g. HBD port | 5012 |
| usr | username | &lt;none&gt; |
| pwd | password | &lt;none&gt; |
| -p | [listening port](../basics/cmdline.md#-p-listening-port) for client communications | &lt;none&gt; |

!!! Note "Standard kdb+ [command line options](../basics/cmdline.md) may also be passed"

## Variables

| Name | Description |
| ---- | ---- |
| .u.x | Connection list. First element populated by [`host1`](#usage) (tickerplant), and second element populated by [`host2`](#usage) (HDB) |

## Functions

Functions are open source & open to customisation.

### upd

Called by external process to update table data. Defaults to [`insert`](../ref/insert.md) to insert/append data to a table.

```q
upd[x;y]
```
Where

* `x` is a symbol atom naming a table
* `y` is table data to add to table `x`, which can contain one or more rows.

### .u.end

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.

```q
.u.end[x]
```
Where x is the date that has ended.

Actions performed:

* finds all tables with the group attribute on the sym column
* calls [`.Q.dpft`](../ref/dotq.md#hdpf-save-tables), with params:
* HDB connection from [`.u.x`](#variables) (second element)
* current directory (note: directory was changed in [`.u.rep`](#urep))
* date passed to this function (`x`) i.e. day that is ending
* `` `sym `` column
* re-apply group attribute to sym column for those tables found in first steps (as clearing the table removed grouped attribute)

### .u.rep

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.

```q
.u.rep[x;y]
```
Where

* `x` is a list of table details, each element a two item list
* symbol for table name
* schema table
* `y` is the tickerplant log details.log comprising of a two item list:
* a long for the log count (null represents no log)
* a file symbol for the location of the current tickerplant log (null represents no log)

Actions performed:

* tables are created using `x`
* if a tickerplant log file has been provided
* log file is replayed using [`-11!`](../basics/internal.md#-11-streaming-execute) to populate tables
* 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).

Loading