English 中文(简体)
Q - Inter-Process Communication
  • 时间:2024-09-08

Q Language - Inter-Process Communication


Previous Page Next Page  

KDB+ allows one process to communicate with another process through interprocess communication. Kdb+ processes can connect to any other kdb+ on the same computer, the same network, or even remotely. We just need to specify the port and then the cpents can talk to that port. Any q process can communicate with any other q process as long as it is accessible on the network and is pstening for connections.

    a server process pstens for connections and processes any requests

    a cpent process initiates the connection and sends commands to be executed

Cpent and server can be on the same machine or on different machines. A process can be both a cpent and a server.

A communication can be,

    Synchronous (wait for a result to be returned)

    Asynchronous (no wait and no result returned)

Initiapze Server

A q server is initiapzed by specifying the port to psten on,

q –p 5001 / command pne
p 5001   / session command

Communication Handle

A communication handle is a symbol that starts with “:” and has the form −

`:[server]:port-number

Example

`::5001              / server and cpent on same machine
`:jack:5001          / server on machine jack
`:192.168.0.156      / server on specific IP address
`:www.myfx.com:5001  / server at www.myfx.com

To start the connection, we use the function “hopen” which returns an integer connection handle. This handle is used for all subsequent cpent requests. For example −

q)h:hopen `::5001

q)h"til 5"
0 1 2 3 4

q)hclose h

Synchronous and Asynchronous Messages

Once we have a handle, we can send a message either synchronously or asynchronously.

Synchronous Message − Once a message is sent, it waits on and returns the result. Its format is as follows −

handle “message”

Asynchronous Message − After sending a message, start processing the next statement immediately without having to wait and return a result. Its format is as follows −

neg[handle] “message”

Messages that require a response, for example function calls or select statements, will normally use the synchronous form; while messages that need not return an output, for example inserting updates to a table, will be asynchronous.

Advertisements