Comments (19)
我觉的你代码写的很标准,看起来比较熟悉我们的用法了。
但是,你对遇到的问题的描述太简略了,比如:”但是这个tid给不到forward_req.set_tid() 中去。”,我没有理解你说的是什么问题。client得到Init的tid,然后吧这个tid传到server的forward函数,但server收不到吗?
from srpc.
第二部分的代码,需要你在init_callback里吧output结果赋response,你代码里没有包括这块的内容。我不知道你是略过了,还是你确实没有写。你的代码结构没有问题,不过,除非你init_routine和forward_routine这两个函数计算量比较大,否则没有必要启动计算任务,直接在函数里写就可以了。
from srpc.
我觉得你的代码写的但是很标准,看起来比较熟悉我们的用法了。 ,你对遇到的问题的描述太简略了,比如:”但是这个tid给不到forward_req.set_tid()中去。 ”,我没明白你说的是什么问题。client得到Init的tid,然后把这个tid传到server的forward函数,但是server收不到吗?
首先感谢回答。
tid是服务端返回给客服端的线程号,在客户端运行时把这个线程号赋值给ForwardRequest发送给客户端的时候tid一直是默认值,
思考了下是Init和Forwad函数是同时启动的两个线程,所以我在中间加了等待,目前ForwardRequest是可以正确得到tid了。
我使用第一种方法:
InitRequest init_req;
init_req.set_encrtyption(encrtyption);
init_req.set_device(device);
init_req.set_use_gpu(use_gpu);
client.Init(&init_req, init_done); // init_done函数中 tid = response->tid();
wait_group.wait(10000);
ForwardRequest forward_req;
forward_req.set_tid(tid);
client.Forward(&forward_req, forward_done);
现在又一个问题,如果我打算一直运行Forward,但是每次发送的数据都不一样,我试了直接写到循环里边;
类似如下 :
while (1)
{
ForwardRequest forward_req;
forward_req.set_tid(tid);
client.Forward(&forward_req, forward_done);
}
发现好像每次执行的Forward函数都是不同线程。
如何让Forward运行的线程保持不变,改变的只是ForwardRequest。
from srpc.
你提问的时候,更好的方法是说明一下你的原始需求,然后我们想解决方案,而不是直接发你的方法和使用这个方法遇到的问题。
我现在只能猜测你的需求。你是希望client在Init的时候得到一个tid,每次请求forward时,把tid发给server,让server在这个tid的线程上执行计算,是这个意思吗?
from srpc.
可能你更原始的需求是,你希望同一client的请求都在同一个线程上执行,因为你有一些thread local的变量?
from srpc.
你提问的时候,更好的方法是说明一下你的原始需求,然后我们想解决方案,而不是直接发你的方法和使用这个方法遇到的问题。
我现在只能猜测你的需求。你是希望client在Init的时候得到一个tid,每次请求forward时,把tid发给server,让server在这个tid的线程上执行计算,是这个意思吗?
不好意思哈
需求是:
1.客户端发送模型到服务端进行模型初始化得到句柄。(全局只做一次)
2.客服端发送得到的句柄和图片到服务端进行模型推理的到结果。
3.只有两个线程,模型初始化一个线程,模型推理一个线程。
from srpc.
第三点只有两个线程,是你自己创建的线程吗?我们的框架本身就是多线程的,而且也无法保障server同一个函数在同一个线程。计算任务,也不能指定线程。你的意思是不是只有两个服务?
from srpc.
你是希望forward和init这两个函数都在固定的线程上执行吗?这么做的目的是什么,是不是有thread local的数据,或者是想串行执行?
from srpc.
第三点只有两个线程,是你自己创建的线程吗?我们的框架本身就是多线程的,而且也无法保障server同一个函数在同一个线程。计算任务,也不能指定线程。你的意思是不是只有两个服务?
不是我创建的,是依赖框架。 是的,只有两个服务。
from srpc.
第三点只有两个线程,是你自己创建的线程吗?我们的框架本身就是多线程的,而且也无法保障server同一个函数在同一个线程。计算任务,也不能指定线程。你的意思是不是只有两个服务?
不是我创建的,是依赖框架。 是的,只有两个服务。
所以,你希望这两个服务分别只有一个线程处理是吗?那么,是因为同一种服务必须只能一个线程处理,还是说,你只是希望每种服务都是串行的执行?
from srpc.
第三点只有两个线程,是你自己创建的线程吗?我们的框架本身就是多线程的,而且也无法保障server同一个函数在同一个线程。计算任务,也不能指定线程。你的意思是不是只有两个服务?
不是我创建的,是依赖框架。 是的,只有两个服务。
所以,你希望这两个服务分别只有一个线程处理是吗?那么,是因为同一种服务必须只能一个线程处理,还是说,你只是希望每种服务都是串行的执行?
希望每种服务都是串行的执行
from srpc.
好的,方法很多。。。所以,你下次提问的话,只需要说SRPC怎么让同一种服务串行执行就可以😂
我给你几个比较好的办法。
from srpc.
好的,方法很多。。。所以,你下次提问的话,只需要说SRPC怎么让同一种服务串行执行就可以😂 我给你几个比较好的办法。
我不是做这方面的,对这些一点都不懂,硬是看了好几天文档和代码
from srpc.
如果使用计算线程,可以这样:
#include <workflow/WFResourcePool.h>
class RemoteServiceImpl : public Remote::Service
{
public:
RemoteServiceImpl() : respool_init(1), respool_forward(1) { }
private:
WFResoucePool respool_init;
WFResourcePool respool_forward;
public:
void Init(InitRequest *request, InitResponse *response, srpc::RPCContext *ctx) override
{
InitTask *task = InitFactory::create_thread_task("init", init_routine, init_callback);
InitInput *input = task->get_input();
input->encrtyption = request->encrtyption();
input->device = request->device();
input->use_gpu = request->use_gpu();
WFConditional *cond = respool_init.get(task);
ctx->get_series()->push_back(cond);
}
}
我们使用只有一个资源的resource pool,当任务需要执行是,必须从resource pool里拿到资源。在init_callback以及forward_callback里,填写response并post会一个资源,让下一个任务可以被调起。关于资源池的文档,可以参考:
https://github.com/sogou/workflow/blob/master/docs/about-resource-pool.md
from srpc.
好的,方法很多。。。所以,你下次提问的话,只需要说SRPC怎么让同一种服务串行执行就可以😂 我给你几个比较好的办法。
我不是做这方面的,对这些一点都不懂,硬是看了好几天文档和代码
不是不是,你代码写的很溜了,对我们的用法理解的很好。我只是说提问题的方式,应该说明原始问题。
from srpc.
上面的用法调用了计算线程。其实你也可以用一个时间为0的定时器,在定时器的回调里执行你的逻辑,同样使用resource pool把定时器任务转换成一个WFConditional。
from srpc.
上面的用法调用了计算线程。其实你也可以用一个时间为0的定时器,在定时器的回调里执行你的逻辑,同样使用resource pool把定时器任务转换成一个WFConditional。
万分感谢。我在研究研究
from srpc.
嗯嗯,有问题随时交流!也麻烦star一下项目啊。
from srpc.
嗯嗯,有问题随时交流!也麻烦star一下项目啊。
okk
from srpc.
Related Issues (20)
- 在SRPCHttpServer上启用trace上报opentelemtry功能异常 HOT 6
- 关于 RPCBuffer 中 read_back 问题 HOT 3
- 关于 RPCBuffer::cut 和 BRPC 中的 attachment 使用的问题 HOT 2
- 是否计划支持linux io_uring? HOT 3
- SRPC性能测试问题 HOT 25
- client.Echo start multi thread,how can I start only one thread? HOT 6
- thrift oneway 无法正确解析 HOT 2
- list<bool>和map返回值不能正确处理 HOT 16
- 想问一下srpc会存在粘包问题么? HOT 1
- in sync mode,It took a long time to get data from server,how can I debug? HOT 18
- srpc::ThriftClient 是否可以访问原生thrift的TMultiplexedProcessor HOT 1
- 有2层namespace时,生成代码出错 HOT 3
- 关于一个server有多个service,不能正常访问 HOT 9
- SRPC支持自定义拦截器吗 HOT 11
- SRPC Http客户端与服务端参数不一致问题 HOT 2
- openeuler下编译时会报错C++标准,建议更新C++标准从11到14 HOT 3
- 应该如何正确的报错呢? HOT 1
- SRPCHttpServer中不支持自定url映射方法 HOT 3
- Protobuf v5 support HOT 4
- 在arm上的编译问题 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from srpc.