Bongjae Chang
2011-12-30 05:01:17 UTC
Hi,
I am trying to support Memcached(http://memcached.org/) client based on
Grizzly.
While I considered several client connection models, I had a question.
If the NIOConnection is shared among multi-threads, is it possible that a
client thread receives the proper reply corresponding to its request?
If a user sends request1 to a server, the server should return response1 and
the client which has sent request1 to the server should receive response1
properly(Request/Response should be pair).
When multi-threads write packets with a shared connection in non-blocking
mode, Grizzly will use the write-queue and the server may send responses in
order.
But I think it is not sure that multi-threads of the client will get the
chance of getting the response in order. For this model, I think packets
should contain the sequence number or id for retrieving proper response.
In addition, it seems that Grizzly doesn't have the convenient API for
retrieving the reply except for write-result future like the following.
For examples,
---
future = connection.write(message);
response = future.get(); // WriteResult#getMessage() is not for read-packet
but written-packet.
---
Any thoughts?
Of course, I can consider another model if sharing the connection in
multi-threads is not supported easily in Grizzly. For examples, if a client
sends packets concurrently to the same server, the client connects each
connection or gets connections in connection pool.
I think that this is trade-off(using more connection resources for
scalability vs reusing only one connection for efficiency)
I wonder I am understanding this correctly and would like to get your
advice.
If I am missing anything or Grizzly already has proper APIs for this, please
let me know.
Thanks.
Regards,
Bongjae Chang
I am trying to support Memcached(http://memcached.org/) client based on
Grizzly.
While I considered several client connection models, I had a question.
If the NIOConnection is shared among multi-threads, is it possible that a
client thread receives the proper reply corresponding to its request?
If a user sends request1 to a server, the server should return response1 and
the client which has sent request1 to the server should receive response1
properly(Request/Response should be pair).
When multi-threads write packets with a shared connection in non-blocking
mode, Grizzly will use the write-queue and the server may send responses in
order.
But I think it is not sure that multi-threads of the client will get the
chance of getting the response in order. For this model, I think packets
should contain the sequence number or id for retrieving proper response.
In addition, it seems that Grizzly doesn't have the convenient API for
retrieving the reply except for write-result future like the following.
For examples,
---
future = connection.write(message);
response = future.get(); // WriteResult#getMessage() is not for read-packet
but written-packet.
---
Any thoughts?
Of course, I can consider another model if sharing the connection in
multi-threads is not supported easily in Grizzly. For examples, if a client
sends packets concurrently to the same server, the client connects each
connection or gets connections in connection pool.
I think that this is trade-off(using more connection resources for
scalability vs reusing only one connection for efficiency)
I wonder I am understanding this correctly and would like to get your
advice.
If I am missing anything or Grizzly already has proper APIs for this, please
let me know.
Thanks.
Regards,
Bongjae Chang