Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel project #517

Closed
kcj3054 opened this issue Dec 5, 2023 · 25 comments
Closed

channel project #517

kcj3054 opened this issue Dec 5, 2023 · 25 comments

Comments

@kcj3054
Copy link

kcj3054 commented Dec 5, 2023

There is a channle in the project, but the channel uses client_pools.. Why? Is the concept of channels necessary for the client pool?? Is this just for testing purposes? Are there any channels needed on the server??

@poor-circle
Copy link
Collaborator

poor-circle commented Dec 5, 2023

Well, I'll add the document of clients_pool/channel later.
The channel is used for load balance, it can connect to multi-server and when send request, it will choice one endpoint to balance the load.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

Wouldn't the concept of a channel be better suited to servers than clients?
What you are saying is that when scaling out, you can connect to the server while load balancing the number of servers that increase?

@poor-circle
Copy link
Collaborator

poor-circle commented Dec 5, 2023

For example, if you have two http server in 1.1.1.1 & 2.2.2.2

std::vector<std::string_view> hosts{"http://1.1.1.1","http://2.2.2.2"};
auto chan = coro_io::channel<coro_http_client>::create(hosts);
while (true) {
       co_await chan.send_request(
          [&](coro_http_client &client,
              std::string_view host) -> Lazy<coro_http::resp_data> {
            co_return co_await client.async_get("/");
        });
}

when you call chan.send_request, it will select one endpoint from 1.1.1.1 & 2.2.2.2, then try to get one connection of this endpoint from global client pool, then execute the lambda you pass to it.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

Also, there is no library that manages sessions connected to the server, so how can I know the sessions connected to me?

Does the library focus more on webserver than socket?

@poor-circle
Copy link
Collaborator

Also, there is no library that manages sessions connected to the server, so how can I know the sessions connected to me?

Does the library focus more on webserver than socket?

You mean server(http or rpc)? the channel is only used in client, and it's transparent for server.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

This refers to the server in coro_rpc_server. For example, it refers to the socket of CPP.

When a connection is made, a session will be maintained per client. Should I implement the sessions containing it separately?

@poor-circle
Copy link
Collaborator

coro_rpc is a rpc framework, so it just care for each RPC call. User can't manage connection/session directly. But maybe I'll consider add some function to control connnection later(for example: close it acitively).

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

Do you have any plans to add the tcp ip session library from yalantinglibs?

@poor-circle
Copy link
Collaborator

poor-circle commented Dec 5, 2023

I think you can just use asio if you want to r/w from socket directly.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

thank you

@qicosmos
Copy link
Collaborator

qicosmos commented Dec 5, 2023

one of the purpose of rpc is hiding low level network, don't expose details to users, to make communication more easier cross processes.

coro_rpc hope to provide a very easy way to develop a network application, the user only need to focus on their business logics, and get rid of so many details, such as async read/write, communication protocol, serialization, route, error handling etc.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

Still, when 100 users connect to the server, shouldn't they know the information about the session in this way so that user 1 wins and user 2 loses?

@qicosmos
Copy link
Collaborator

qicosmos commented Dec 5, 2023

the information should be maintained by business logic, similar with http session cookie.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

I have a question. From the answers above, I get the feeling that coro_rpc is stateless, so is what coro_rpc provides stateless? Is it stateful? If it's sateful, you should be able to manage the session yourself, but I'm really curious because the answer above says you can't do that.

in coro_rpc example

@poor-circle
Copy link
Collaborator

you are right, coro_rpc is stateless.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

We are currently investigating coro_rpc, and this is something that other team members are curious about and I am also curious about: https://alibaba.github.io/yalantinglibs/en/coro_rpc/coro_rpc_introduction.html#real-time-tasks-and-non-real- time-tasks

Looking at the description of coro_rpc in the link, it appears that communication is maintained while being stateful when the connection is connected. However, when you said it was stateless, I was curious. Is there a way to write an explanation in the document or check it in the code?

Instead of creating and maintaining the connection in the client.connect part, do you disconnect the connection immediately after the client.call?

@poor-circle
Copy link
Collaborator

poor-circle commented Dec 5, 2023

We are currently investigating coro_rpc, and this is something that other team members are curious about and I am also curious about: https://alibaba.github.io/yalantinglibs/en/coro_rpc/coro_rpc_introduction.html#real-time-tasks-and-non-real- time-tasks

Looking at the description of coro_rpc in the link, it appears that communication is maintained while being stateful when the connection is connected. However, when you said it was stateless, I was curious. Is there a way to write an explanation in the document or check it in the code?

Instead of creating and maintaining the connection in the client.connect part, do you disconnect the connection immediately after the client.call?

This document just say that you can response the rpc result directly by return statement, or use the handle to delay the response to avoid block the network io(for example, run a heavy work in other thread). It doesn't means that the rpc call is stateful.

@poor-circle
Copy link
Collaborator

Instead of creating and maintaining the connection in the client.connect part, do you disconnect the connection immediately after the client.call?

coro_rpc_client won't disconnect immmediately unless error happen or you close it manually.

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

The simplest proof is to check whether the session ID changes after the connection is established. I have confirmed that conn_id exists in coro_rpc_server.hpp. Is it possible to print conn_id every time there is communication after connection?

@poor-circle
Copy link
Collaborator

The simplest proof is to check whether the session ID changes after the connection is established. I have confirmed that conn_id exists in coro_rpc_server.hpp. Is it possible to print conn_id every time there is communication after connection?

In debug mode server will print it

@kcj3054
Copy link
Author

kcj3054 commented Dec 5, 2023

When in debug mode, the server responds only when connecting for the first time, so I want to print out whether the connection ID changes after connecting what I want. I'm really curious.

@poor-circle
Copy link
Collaborator

When in debug mode, the server responds only when connecting for the first time, so I want to print out whether the connection ID changes after connecting what I want. I'm really curious.

OK, I'll add it later.

@poor-circle
Copy link
Collaborator

See #521 now you can get some context info by coro_rpc::context:

  1. has_close(): if connection close
  2. close(): close connection actively
  3. set_tag/get_tag: set/get user-defined connection level context info
  4. get_connect_id(): get the unique id of connect. You can print it or use it as the key of connection context.

@kcjkcj3054
Copy link

kcjkcj3054 commented Dec 26, 2023

Hello, get_connect_id was confirmed as a unique id in coro_rpc_client, what I want to check is the conn_id in coro_rpc_server.hpp.

According to the contributors, coro is stateless, but if the conn_id does not change in the client-server connection, it can be confirmed as stateful rather than stateless. Can I try modifying the conn_id?

What part of coro_rpc_server.hpp can I call by entering connec_id?

@poor-circle
Copy link
Collaborator

get_connect_id will return conn_id_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants