Search code examples
thrift

Redirecting Thrift service requests to fork process running on same machines


I have Thrift servers developed in c++ and running on Linux machine. If client sends a request to thrift server, my server will fork one process and concurrent request from same connection should handle by fork process.

Is there any way by which I can redirect the thrift requests coming from the clients to fork process ?


Solution

  • You can handle Thrift clients in forked children of your server but you will have to write a custom Thrift server to do it.

    TLDR: When you call fork(), the child process inherits copies of all open file descriptors. So in essence, any Socket the parent had is automatically available to the child. While none of the built in Thrift servers currently fork full child processes to handle client connections, there is a Python server that does. In a given process, Python only runs one thread at a time in user code, so forking is the only way to get parallelism. C++, on the other hand, has threads (lightweight processes), so the existing C++ servers create threads to scale out, rather than processes.