I'm a bit confused about how a Tcl server works. I've been coding a small version that works pretty well for my local application but I'd like to understand it better conceptually. I have Ashok Nadkarni's book and used it as a starting point and thought I understood the examples about how the server does not block. And, I went through some of the code from the tclhttpd3.5.1 server to get started (some months ago, now, and was using that general method of using state to repeatedly read until I was pointed to using coroutines).
I think my code has been working because one desktop application with very rapidly processed requests rarely has any issues of blocking. I thought all was correct because the previous session could be restored quickly even though multiple database requests are (or appear to be) processed concurrently.
My plan was to use a small number of web sockets to handle the SQlite database requests and use HTTP for any audio/video requests. (The application is like a digital study library.) When I started to code the audio parts to play, while leaving the rest of the UI active such that database requests could be made while it played, I started to wonder more about the way I structured it. I got it all to work for my particular case and, it likely, will handle everything quickly but I'd like to understand better.
I was stupidly thinking that the server just handles everything without ever blocking because it can handle multiple connections, but I put all my code in the same script as the server code. So, if I "fabricate" a blocking scenario, the server requests pile up but are eventually fulfilled. Although the server doesn't block, if one of the requests is time consuming, the program itself blocks until each request completes, apart from an exception like fcopy
with -command
option. I know that source
can be used to break the script into component scripts but that doesn't make it non-blocking.
If one was going to use Tcl as a "real" server rather than just for one application, how are the requests to be processed without blocking each other? I mean are they to be executed as separate threads, separate child processes, separate interpreters? Maybe those three are almost the same, I don't know.
Should the server script call multiple instances of other scripts to fulfill the requests rather than calling procedures within the same "single-instance" script; and the operating system will process them as efficently as possible? But, if so, how is information shared between the processes? If two similar requests arrived at nearly the same time, could two spearate instances of the same script be loaded to fulfill the requests concurrently, such that one does not block the other?
In looking over the code in the tclhttpd3.5.1 server, it appears that, at times, he is using multiple interpreters and aliasing something; but I don't follow what's going one there.
I apologize for not knowing the proper terminology. Thank you for any guidance you may be able to provide.