StormHub / NetUV

.Net standard/Core binding for Libuv
Other
76 stars 20 forks source link

Port DotNetty's Attribute and Add WorkerPool #72

Closed egmkang closed 1 year ago

egmkang commented 6 years ago

port DotNetty's AttributeKey and AttributeMap add WorkerPool as a default pattern and rewrite the LoopThread sample using WorkerPool

StormHub commented 6 years ago

:white_check_mark: Build NetUV 0.2.140-aybivxjt completed (commit https://github.com/StormHub/NetUV/commit/2917d6575a by @egmkang)

StormHub commented 6 years ago

Thanks for the PR! I have a few things to clarify and understand a bit more about the problems.

What is the scope of the attribute map (e.g. per thread or tcp handle)? If you having issues with passing callbacks through handles, could you give me an example? e.g. All handles have a property called 'UserToken' to save some sort of context object, is it not so easy to work with?

egmkang commented 6 years ago

hi

every tcp handle it's own attribute map, to store something like property. for example, each one Tcp have a property named SessionID, in logic layer, i can find out which tcp had a SessionID:1, so i can send message to this tcp directly. without attribute map, this is some ways to solve this problem. i can build a global map to store each Tcp's data, just like Map<Tcp, TcpData>, and on each callback, go to the global map to search the data. another way, i can let MyTcp inherit the class Tcp, and MyTcp has a property named SessionID. Just need to be able to construct MyTCP. (this way need to modify a lot of codes)

another problem, i have to listen two ports(maybe more ports and more protocols), one using protocol named ProtocolA, one using protocol named ProtocolB. if i want to solve this problem, i must give PortA's Tcp a ProtocolADecoder, and B is B's. in libuv, there is two way to share one fd to another event loop. one way is uv_write2, one way is SO_REUSEPORT. SO_REUSEPORT looks good, and the codes are simpler. uc_write2 drops the context, so i should use one global map to save the context, to identify which TCP is accepted from which port.

that are my two real problems to solve.

egmkang commented 6 years ago

the real problem is more complex. for example, you can simplely using QueueWriteStream to send one packet. in practice, most packet is very small, just 10~50 Bytes. but one network adapter has its limit. the openstack's virtual network adapter can process about 150k packet one second. aws's virtual network adapter, maybe, can process about 500k packet one second. so in logic layer, you must use gather write. or buy more vm.