Replies: 5 comments 9 replies
-
Hi @pha3z it's a great point. The primary reason I didn't do something like this is I wanted to opt for ease of use more than anything, and the string variant is pretty simple. For personal projects, I generally don't rely on the ip:port for anything other than disconnection. I use the metadata as a means of exchanging session state (which also identifies the user, etc). Cheers, Joel (moving to discussion; if there's consensus on this, happy to add to the backlog, or if you/someone has a PR that is in line with the spirit of the library, I'd be open to a merge) |
Beta Was this translation helpful? Give feedback.
-
What is the metadata you're referring to? In "void MessageReceived(object sender, MessageReceivedEventArgs args)", I don't see any identifying information available except for args.IpPort. |
Beta Was this translation helpful? Give feedback.
-
Back on the string ip port issue, so everything in Watson resolves around string -- even Server.Send(). I presume Watson must translate the string to an underlying open socket. So there's a cost in that direction also, isn't there? |
Beta Was this translation helpful? Give feedback.
-
Since we're even discussing this, I'm going add another point for the sake of posterity: A HashSet completely eliminates key storage. If the string is available as a reference in ClientMetaData (which I'm guessing its not), you can use a custom IEqualityComparer to use HashSet instead of dictionary and still key on the ipPort. Also, for what its worth, the default HashSet in .net is a pitiful animal. They really botched it. I easily modified the .NET HashSet to support AddOrReplace() so that you can do extremely rapid additions to the hashset. It outperforms a dictionary due to the fact that you don't store key information. If the idea of optimizing the address handler to use byte[] address hashing actually takes off, its worth considering going a step further and completely replacing the ConcurrentDictionary with a custom ConcurrentHashSet. I have a feeling nobody is actually interested in this. But I thought its worth noting. Also I really wish .NET BCL would incorporate a ConcurrentHashSet and make the default HashSet Non-Sucking. |
Beta Was this translation helpful? Give feedback.
-
It just occurred to me: do we even need the dictionary lookup to send data to a client? Would it be possible to expose a function delegate or some other type that would allow sending data to a client without doing a hash lookup at all? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not sure how you are typically tracking connected users, but for myself (and I guess this is pretty common), an easy technique is to hash the IpPort string of user to form a dictionary key.
This might be an excessive micro-op (??) but some people might appreciate it:
If you're dealing with hi-thru-put of a LOT of messages, you could save some computation if hashing could be done on something better than a string. You could expose all IpPort combinations in a (16 byte, 2 byte) tuple or 18byte array to support IPv6:Port combinations. Hashing 18 bytes is going to be substantially faster than hashing a string representation.
I actually would prefer the byte-array version myself since it allows you to pass around an array pointer instead of the numeric ip values.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions