Repository navigation
#174 Speed up messageId generation - #175
Conversation
|
Tests are all green on my end. @eolivelli @diegosalvi thought on this? |
| private final ExecutorService callbackexecutor = Executors.newCachedThreadPool(); | ||
| private final ExecutorService executionserializer = Executors.newFixedThreadPool(1); | ||
| private String id = UUID.randomUUID().toString(); | ||
| private String id = CHANNEL_ID_GENERATOR.incrementAndGet() + ""; |
There was a problem hiding this comment.
This ID is only used in the toString. In NettyChannel, the id was already a long
There was a problem hiding this comment.
if this is only a local variable, not related to the write protocol, you can change it to a "long"
btw generating JVMChannels shouldn't be on the hot paths (read/write), so it is not a big deal to change it
| private final ExecutorService callbackexecutor = Executors.newCachedThreadPool(); | ||
| private final ExecutorService executionserializer = Executors.newFixedThreadPool(1); | ||
| private String id = UUID.randomUUID().toString(); | ||
| private String id = CHANNEL_ID_GENERATOR.incrementAndGet() + ""; |
There was a problem hiding this comment.
if this is only a local variable, not related to the write protocol, you can change it to a "long"
btw generating JVMChannels shouldn't be on the hot paths (read/write), so it is not a big deal to change it
| public class JVMChannel extends Channel { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(JVMChannel.class.getName()); | ||
| private static final AtomicLong ID_GENERATOR = new AtomicLong(); |
There was a problem hiding this comment.
why are you using a "static" variable ?
this smells to me because we have two cases (I didn't check the wire protocol):
- this ID is unique in the scope of the connection (channel?), then it is better to use an instance field
- this ID is unique globally......then having a static field is a bad way to generate this value, because every JVM will have its own counter
I guess we are in case 2), so I would use a simple instance field
There was a problem hiding this comment.
The protocol works like this:
- jvm1 sends a request_message with messageID=x
- jvm1 stores the entries <messageID, callback> <messageID, request_message>, this are stored in the channel
- jvm2 receives request_message and sends a reply_message with replyMessageID=request_message.messageID and messageID=k
- jvm1 receives the reply_message and reads the replyMessageID to invoke the right callback and stuff
Even if the request_message.messageID is stored at channel level, the whole request_message gets passed to callbacks which comes from outside the channel (eg. see CacheClient#touchEntry). So I think it's good to have request_messages' messageID unique across the jvm channels
The reply messageID can conflict with the messageID of the request, but reply_message.messageID is never used. This can also happen with uuid v4 (with a very lower chance)
There was a problem hiding this comment.
the messageId is unique only in the scope of a "Channel" and actually you have two series of ids, once per each side of the connection.
even if the message id is leaked in callback, it is a useless information for the caller
I think that having a "static" id generator is only misleading.
I am trying to find a valid usecase, what would you do with a unique id per-JVM (classloader) ? logging the message id and correlate errors ?
There was a problem hiding this comment.
Yes logging and tracking the message. With a local message id we would have to expose and log the channel id too.
Right now there are no such logs, It was just a thought for future. I will make the generator local
| private volatile SocketChannel socket; | ||
| private static final Logger LOGGER = Logger.getLogger(NettyChannel.class.getName()); | ||
| private static final AtomicLong idGenerator = new AtomicLong(); | ||
| private static final AtomicLong ID_GENERATOR = new AtomicLong(); |
There was a problem hiding this comment.
see my comments on JVM Channel
|
Pushed the fix for the static (now local) message id generator |
eolivelli
left a comment
There was a problem hiding this comment.
LGTM
Do we have CI somewhere ?
I suggest to setup GitHub actions, in order to have immediate feedback on the goodness of the change.
|
Yes we are lacking CI and pre-merge checks. Last week I created #176 |
|
@dmercuriali see #177 |
c8b9e3b to
62f3d44
Compare
62f3d44 to
db02aee
Compare
|
@dmercuriali |
|
Yes, It failed after 15 runs on my end. The test expects a client to not receive an invalidation request, but sometimes the client connection to the cache-server is closed earlier and the test fails because the cache-entry it expects to find is null. Seems unrelated to this PR |
|
Now this is failing: Here a client is stopped and then we check the ConnectedClients of the server. The assert fail because the server has yet to do the -1 on the counter. I think this can be merged |
Change messages and replies id from uuid to long to speedup the id generation.
The ID is only stored by the sender of the first request, receivers of the message use the messageID to set the replyMessageID, so a simple AtomicLong per host should suffice.
I kept the (reply)messageID as String to avoid changing a lot of places