c++客户端:高并发支持

void *test(void *ptr) {
    auto& session = *(nebula::Session*)ptr;
    auto t0 = get_current_ms();
    auto result = session.execute("GO FROM \"1\" OVER follow reversely where $$.user.last_active_ts > 1612180980");
    if (result.errorCode() != nebula::ErrorCode::SUCCEEDED) {
        std::cout << "Exit with error code: " << static_cast<int>(result.errorCode()) << std::endl;
        return nullptr;;
    }
    auto t1 = get_current_ms();
    //std::cout << *result.data();
    std::cout << "time cost " << t1-t0 << "\n";
    return nullptr;
}


for(int i = 0; i < n; ++i){
    pthread_create(&tid,NULL,test, & session);
}

通过上面的代码模拟并发查询,发现越到后面,查询耗时越大。
一个session的多次查询是串行排队的吗?

高并发查询应该如何实现?

可以用asyncExecute

异步并没有提高并发吞吐量。
同时编程模式本身是同步模式,改用异步还得额外使用furture等待。

void *test2(void *ptr) {
    auto& session = *(nebula::Session*)ptr;
    auto t0 = get_current_ms();
    std::promise<int> prom;
    std::future<int> fut = prom.get_future();
    session.asyncExecute("GO FROM \"1\" OVER follow reversely where $$.user.last_active_ts > 1612180980", [&prom](nebula::ResultSet &&ret) { prom.set_value(1);});
    auto n = fut.get();
    auto t1 = get_current_ms();
    //std::cout << *result.data();
    std::cout << "time cost " << t1-t0 << "\n";
    return nullptr;
}

我建议你那边 不要多线程共用1个session,每个线程用1个session,
可以把pool 设置的大一点,我们在研发过程也不这么用的