Thrift Java Servers Compared(二)

2014-11-24 03:11:05 · 作者: · 浏览: 2
seCode.Success; } \\

The results are as expected. THsHaServer is able to process all the requests concurrently, while TNonblockingServer processes requests one at a time.

结果正如期望。THsHaServer能同时并行处理所有请求,而TNonblockingServer一次处理一个。< http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KCgo8aDI+ClRIc0hhU2VydmVyIHZzLiBUVGhyZWFkZWRTZWxlY3RvclNlcnZlcjwvaDI+CjxwPlRocmlmdCAwLjggaW50cm9kdWNlZCB5ZXQgYW5vdGhlciBzZXJ2ZXIsIFRUaHJlYWRlZFNlbGVjdG9yU2VydmVyLiBUaGUgbWFpbiBkaWZmZXJlbmNlIGJldHdlZW4gVFRocmVhZGVkU2VsZWN0b3JTZXJ2ZXIgYW5kIFRIc0hhU2VydmVyIGlzIHRoYXQgVFRocmVhZGVkU2VsZWN0b3JTZXJ2ZXIgYWxsb3dzIHlvdSB0byBoYXZlIG11bHRpcGxlIHRocmVhZHMgZm9yIG5ldHdvcmsKIEkvTy4gSXQgbWFpbnRhaW5zIDIgdGhyZWFkIHBvb2xzLCBvbmUgZm9yIGhhbmRsaW5nIG5ldHdvcmsgSS9PLCBhbmQgb25lIGZvciBoYW5kbGluZyByZXF1ZXN0IHByb2Nlc3NpbmcuIFRUaHJlYWRlZFNlbGVjdG9yU2VydmVyIHBlcmZvcm1zIGJldHRlciB0aGFuIFRIc0hhU2VydmVyIHdoZW4gdGhlIG5ldHdvcmsgaW8gaXMgdGhlIGJvdHRsZW5lY2suIFRvIHNob3cgdGhlIGRpZmZlcmVuY2UsIEkgcmFuIGEgYmVuY2htYXJrIHdpdGggYSBoYW5kbGVyCiB0aGF0IHJldHVybnMgaW1tZWRpYXRlbHkgd2l0aG91dCBkb2luZyBhbnl0aGluZywgYW5kIG1lYXN1cmVkIHRoZSBhdmVyYWdlIGxhdGVuY3kgYW5kIHRocm91Z2hwdXQgd2l0aCB2YXJ5aW5nIG51bWJlciBvZiBjbGllbnRzLiBJIHVzZWQgMzIgd29ya2VyIHRocmVhZHMgZm9yIFRIc0hhU2VydmVyLCBhbmQgMTYgd29ya2VyIHRocmVhZHMvMTYgc2VsZWN0b3IgdGhyZWFkcyBmb3IgVFRocmVhZGVkU2VsZWN0b3JTZXJ2ZXIuPC9wPgo8cD5UaHJpZnQgMC440v3I68Ht0rvW1nNlcnZlcqOsVFRocmVhZGVkU2VsZWN0b3JTZXJ2ZXKho1RUaHJlYWRlZFNlbGVjdG9yU2VydmVyus1USHNIYVNlcnZlctfutPO1xLK7zazKx9TK0O3E49PQzqrN+MLnSS9Pt9bF5LbguPbP37PMoaPL/LGjs9bBvbj2z9+zzLPYo6zSu7j2zqrBy7SmwO3N+MLnSS9PLCDSu7j2tKbA7cfrx/Oho1RUaHJlYWRlZFNlbGVjdG9yU2VydmVy1NrN+MLnaW/Kx8a/vrHKsbHtz9axyFRIc0hhU2VydmVyusOho86qwcvP1Mq+y/vDx7XEsrvNrKOsztLUy9DQ0ru49rSmwO26r8r9srvX9sjOus7KwsGivLS3tbvYtcRiZW5jaG1hcmujrAogsqKy4sG/srvNrGNsaWVudMr9wb/PwrXExr2++dHTs9m6zc3MzcLBv6GjztLKudPDMzLP37PMtcRUSHNIYVNlcnZlciC6zTE2uaTX98/fs8wvMTZzZWxlY3Rvcs/fs8y1xFRUaHJlYWRlZFNlbGVjdG9yU2VydmVyoaM8L3A+CjxpbWcgc3JjPQ=="https://www.cppentry.com/upload_files/article/76/1_djqym__.png" alt="\">\

The result shows that TThreadedSelectorServer has much higher throughput than THsHaServer while maintaining lower latency.

结果显示TThreadedSelectorServer比THsHaServer有更高的吞吐量且更低的延迟。

TThreadedSelectorServer vs. TThreadPoolServer

Finally, there is TThreadPoolServer. TThreadPoolServer is different from the other 3 servers in that:

最后是TThreadPoolServer, TThreadPoolServer和其他3个servers不同地方在于:

  • There is a dedicated thread for accepting connections.
  • Once a connection is accepted, it gets scheduled to be processed by a worker thread in ThreadPoolExecutor.
  • The worker thread is tied to the specific client connection until it’s closed. Once the connection is closed, the worker thread goes back to the thread pool.
  • You can configure both minimum and maximum number of threads in the thread pool. Default values are 5 and Integer.MAX_VALUE, respectively.
  • 有一个专用线程接受连接
  • 一旦一个连接被接受了,被安排给ThreadPoolExecutor中一个工作线程来处理
  • 这个工作线程服务该指定client连接直到关闭。一旦该连接关闭,该工作线程回到线程池
  • 你可以配置线程池的最小和最大线程数。对应的默认值事5和Integer.MAX_VALUE

    This means that if there are 10000 concurrent client connections, you need to run 10000 threads. As such, it is not as resource friendly as other servers. Also, if the number of clients exceeds the maximum number of threads in the thread pool, requests will be blocked until a worker thread becomes available.

    这意味着如果有10000个并发client连接,你需要运行10000个线程。就本身而论,这不如其他servers对资源友好。并且,如果client的数量超过线程池的最大数值,请求将被阻塞住直到有工作线程可用。

    Having said that, TThreadPoolServer performs very well; on the box I’m using it’s able to support 10000 concurrent clients without any problem. If you know the number of clients that will be connecting to your server in advance and you don’t mind running a lot of threads, TThreadPoolServer might be a good choice for you.

    话虽如此,TThreadPoolServer表现的非常好;我用它支撑10000个并发连接没有任何问题。如果你能提前知道你的client数目并且也不介意多一点线程,TThreadPoolServer对你可能是个好选择。

    \\

    Conclusion

    I hope this article helps you decide which Thrift server is right for you. I think TThreadedSelectorServer would be a safe choice for most of the use cases. You might also want to consider TThreadPoolServer if you can afford to run lots of concurrent threads. Feel free to send me email atmapkeeper-users@googlegroups.com or post your comments here if you have any questions/comments.

    我希望这篇文章能帮你决定哪种Thrift server适合你。 我觉得对于多数情况TThreadedSelectorServer是个安全的选择。如果你你可以接受运行大量并发进程,你也可以考虑TThreadPoolServer。

    Appendix A: Hardware Configuration

    Processors:     2 x Xeon E5620 2.40GHz (HT enabled, 8 cores, 16 threads)
    Memory:         8GB
    Network:        1Gb/s 
          
           
    OS:             RHEL Server 5.4 
           Linux 2.6.18-164.2.1.el5 x86_64
          

    Appendix B: Benchmark Details

    pass