chenBright opened a new pull request, #3422:
URL: https://github.com/apache/brpc/pull/3422
### What problem does this PR solve?
Issue Number: resolve N/A
Problem Summary:
The previous Stream implementation created a fake `Socket` for every Stream
to reuse `SocketId`, reference counting, object lookup, and the Socket write
queue.
This introduced unnecessary coupling and an inefficient write path:
```text
StreamWrite -> fake Socket queue -> Stream frame packing -> host Socket
queue -> network
```
As a result, each Stream message passed through two Socket queues and could
require two bthread scheduling operations before being sent. It also made
Stream lifecycle management depend on `SocketConnection` and
fake-Socket-specific behavior, increasing the complexity of failure handling,
reference management, and object recycling.
Since `VersionedRefWithId` already provides versioned IDs, O(1) lookup,
reference counting, and deferred recycling, creating a fake Socket solely for
these capabilities is unnecessary.
### What is changed and the side effects?
Changed:
- Refactored `Stream` to inherit directly from `VersionedRefWithId<Stream>`.
- Removed the fake Socket and the `SocketConnection` dependency from Stream.
- Simplified the write path to pack a complete Stream message and enqueue it
directly to the real host Socket:
```text
StreamWrite -> Stream frame packing -> host Socket queue -> network
```
Side effects:
- Performance effects:
- Removes one queue traversal from every Stream write.
- Avoids the potential extra bthread scheduling operation introduced by
the fake Socket.
- Reduces the Stream lookup path from `StreamId -> fake Socket -> Stream`
to `StreamId -> Stream`.
- Breaking backward compatibility:
---
### Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow [Contributor Covenant Code of
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]