What is the most "expensive" for a server: connections opened, send/receive messages or connections/deconnections?
What is the most expensive for a server
(using Java NIO Selec开发者_如何学编程tor and SocketChannel, but I guess the language and library don't matter anyway)- keeping many client connections opened
- many client connections/deconnections
- receiving many messages from clients and answering many messages to clients
When solving performance issues, never trust any guesses or even "common sense". Always measure. Always profile. In case of doubt write sample applications that do only one of the points in question (its usually quite easy to do). Again and again you will be surprised.
I think the second one will be the most expensive, if you use a good object pooling mechanism for the first one. If not, then keeping hundreds of connections open, is going to become a serious issue.
Sending and receiving messages shouldn't be that of a hassle.
精彩评论