Interprocess Communication (IPC) · IPC Overview · Practice Question
How Are Ports Typically Configured in a kdb+ Tick Setup?
Question
How are ports typically configured across the processes in a kdb+ tick system? How does each process know what port to listen on and where to find the other processes?
Solution
The KX tick example ("kdb+tick") uses these ports by default:
Tickerplant: 5010
RDB: 5011
HDB: 5012Each process is started with its own port via the -p flag:
q tick.q sym /data/tplogs -p 5010 # tickerplant: schema file sym.q, logs in /data/tplogs
q tick/r.q localhost:5010 localhost:5012 -p 5011 # RDB: connects to the TP and the HDB
q /data/hdb -p 5012 # HDB: loads the database directoryInside a script such as r.q, the addresses of the other processes are read from .z.x, the list of command-line arguments (as strings):
tpAddr: .z.x 0 / "localhost:5010"
hdbAddr: .z.x 1 / "localhost:5012"
tp: hopen `$":", tpAddr / open a handle to the tickerplantExplanation
kdb+ has no built-in port registry or service discovery. Port assignments are managed by convention and passed between processes via command-line arguments.
The -p flag sets the port a q process listens on:
q script.q -p 5010 # listen on port 5010.z.x is the list of command-line arguments. Each process reads the addresses of other processes it needs from this list at startup. The order of arguments is a convention defined by the startup scripts:
# RDB startup: arg[0]=tickerplant, arg[1]=HDB
q tick/r.q localhost:5010 localhost:5012 -p 5011Port conventions vary by organisation. The KX tick example uses 5010–5012 for the tickerplant, RDB and HDB; other processes (gateways, chained tickerplants, writers) are given ports by each organisation. Common variations:
- Add a digit prefix for environment:
15010for prod,25010for UAT,35010for dev - Add an asset class suffix:
5010for equities,5020for FX,5030for futures - Use a multiplier scheme:
50100for tickerplant of system 10
Process registries are used in larger systems instead of hardcoded port arguments. A dedicated q process maps process names to addresses, and each starting process asks it where to connect. For example, if the registry defines a function getAddr that returns an address such as `:host1:5010:
registry: hopen `:reghost:5000 / connect to the registry
tp: hopen registry (`getAddr; `tp) / ask it for the tickerplant's address, then connectThis allows processes to be restarted on different ports without changing all their dependents' startup scripts — only the registry needs to be updated.
Within a single machine, processes connect using localhost or :: (the loopback address). Across machines, the full hostname or IP address is used.