Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

C++多线程预测,使用brpc包装,QPS太低

Open dancingpipi opened this issue 7 years ago • 9 comments

fluid 1.4 代码如下:

int Classifier::predict(paddle::PaddleTensor &image_tensor, paddle::PaddleTensor &audio_tensor, std::vector<float> &output, const int index){
    int ret_code = 0;
    try {
        std::vector<paddle::PaddleTensor> tensor_feeds;
        std::vector<paddle::PaddleTensor> outputs;
        tensor_feeds.emplace_back(std::move(image_tensor));
        tensor_feeds.emplace_back(std::move(audio_tensor));

        auto predictor = _main_predictor->Clone();
        predictor->Run(tensor_feeds, &outputs, 1);

        const size_t num_elements = outputs.front().data.length() / sizeof(float);

        auto *output_data = static_cast<float *>(outputs.front().data.data());
        output.assign(output_data, output_data + num_elements);
    } catch (const std::exception &err){
        LOG(ERROR) << "error occur in predict : " << err.what();
        ret_code = -1;
    }
    return ret_code;
}

QPS特别低,请问下原因,我的使用姿势正确吗?

dancingpipi avatar Aug 27 '19 14:08 dancingpipi

auto predictor = _main_predictor->Clone(); 这个应该只在初始化调用一次,不应该写在predict里面

lgone2000 avatar Aug 28 '19 01:08 lgone2000

auto predictor = _main_predictor->Clone(); 这个应该只在初始化调用一次,不应该写在predict里面

能说一下原因么,因为使用brpc封服务,如果预先设定predictor,brpc不是特别好包

dancingpipi avatar Aug 28 '19 01:08 dancingpipi

clone是为了多线程使用, 相当于重新初始化了一次模型。如果单线程调用你就用_main_predictor 就可以,不需要clone, 如果多线程使用,你需要在每个线程初始化时,clone一个, 而不是每次预测调用一次。

lgone2000 avatar Aug 28 '19 02:08 lgone2000

clone是为了多线程使用, 相当于重新初始化了一次模型。如果单线程调用你就用_main_predictor 就可以,不需要clone, 如果多线程使用,你需要在每个线程初始化时,clone一个, 而不是每次预测调用一次。

你的意思是Clone会很耗时对吗,但是我自己测了一下,clone的耗时大概在0.5~1ms之间,并不会有太大的时间消耗啊

dancingpipi avatar Aug 28 '19 02:08 dancingpipi

image 我用单线程跑速度大概是5ms,上面的图是我用多线程跑的,10个线程下inference速度也是线性增长的

dancingpipi avatar Aug 28 '19 10:08 dancingpipi

请问你用的版本是哪个,是跑 X86 还是 GPU 模型呢。您是厂内用户吧,我们可以 hi 联系。

Shixiaowei02 avatar Aug 28 '19 10:08 Shixiaowei02

我在GPU上跑的

在2019年08月28日 18:35,石晓伟 写道:

请问你用的版本是哪个,是跑 X86 还是 GPU 模型呢。您是厂内用户吧,我们可以 hi 联系。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

dancingpipi avatar Aug 28 '19 10:08 dancingpipi

请问是否方便提供模型呢

Shixiaowei02 avatar Aug 28 '19 10:08 Shixiaowei02

Since you haven't replied for more than a year, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过一年未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

paddle-bot-old avatar Aug 31 '20 09:08 paddle-bot-old