Sometimes I just go around in circles wondering whether adding a thread queue
开发者_如何转开发 with a single thread querying and updating a database server at the cost of a worker thread
processing user requests would be efficient resources usage or not, and how would it impact overall performance of the application in terms of number of replies/sec
?
However, since I am merely a hobbyist with no real business projects, I usually end up giving up because of too much thinking about it. I research but I find no relevant answers.
SO what might be other factors that one shall take into account when programming high performance I/O (networking specifically) applications in both managed and un-managed environments?
One of the areas that would be good research for you would be Operating Systems Concepts. Many Computer Science degrees offer a course in this.
Sounds like you have a hypothetical application on your machine making requests of a database and you are interested if threading this hypothetical application will increase its performance.
Having worked as a performance tester I can tell you system performance is all about trade offs and priorities. i.e. do you want the UI super responsive, or do you want to use the absolute minimum system resources?
In this case you are lucky, the resources you want to balance are not in contention for each other. The Database Side of things is what we call I/O and the threading side of things is CPU. Applications tend to be I/O bound or CPU bound, a few are both. In an I/O bound application switching in a faster CPU will not speed things up much, and vice-versa.
If you add additional threads this will help if and only if your network has time for extra network IO. Adding extra threads will not increase the load on the CPU in a way that it won't be able to handle, since the request will be made to the database and the thread will block. Once the request is returned to your machine an interrupt will be thrown and you thread will be pulled off of the waiting Queue.
The real question is: How nice do you want to be to your database?
精彩评论