Search code examples
kdb

startup script for multiprocess q


I'm trying to start up kdb with multiple processes to use to write scripts with KDB developer. I understand that the processes that are set up need to be done so outside of the master process.

I have attempted to do this with a function in my .bashrc that creates 7 instances which are expecting a maximum of 8 processes. I then start up a final process with developer. When I do this and try to connect, my OS informs developer that the connections are refused. Could you advise on the correct way to start 8 processes to use with IPC in KDB? This is my multiple process startup function in .bashrc:

mq() {
    echo "Spawning 7 q processes";
    q -s -8 -p 20001;
    q -s -8 -p 20002;
    q -s -8 -p 20003;
    q -s -8 -p 20004;
    q -s -8 -p 20005;
    q -s -8 -p 20006;
    q -s -8 -p 20007;
}

This is the code in .bashrc to start developer:

# Assumes user name is claude and opens Q with 8 threads. (to build separate processes use a negative number) 
alias q='rlwrap -r q -s -8'
# Developer set to open with 8 threads. (to build separate processes use a negative number)
alias developer='source /pathToDir/developer/config/config.profile; rlwrap -r q /pathToDir/developer/launcher.q_'

To start all this up, I open one terminal and type mq then open another terminal and type developer Once in developer, I assign a handle to each process like this: {hopen("::",string[20000+x])}each 1+til 7 Then the system tells me that the connection is refused.

How should I do this?

Thanks and regards,


Solution

  • I think you should use & when start multiple q processes in your shell script:

    mq() {
                echo "Spawning 7 q processes";
                    q -s -8 -p 20001 &
                        q -s -8 -p 20002 &
                            q -s -8 -p 20003 &
                                q -s -8 -p 20004 &
                                    q -s -8 -p 20005 &
                                        q -s -8 -p 20006 &
                                            q -s -8 -p 20007 &
                                    }
    mq
    

    Without &, only 1 process will be open at one time. It work for me: ./mq.sh

    bchen@homer:~$ ./mq.sh 
    Spawning 7 q processes
    q)q)q)q)q)q)
    

    In q session:

    q){hopen("::",string[20000+x])}each 1+til 7
    4 5 6 7 8 9 10i