几次成功连接后,curl curle_couldnt_connect错误

时间:2019-02-19 22:29:27

标签: c++ curl

我正在通过openAI gym中的http连接使用C++(由python开发),该连接在 [https://github.com/openai/gym-http-api/tree/master][1]。通过调用gym_http_server.py创建服务器,并且C++目录中提供cpp-binding代码。我也用C ++开发了一个简单的全连接神经网络,并实现了一种算法来学习玩gym中可用的一些游戏。当我的神经网络较小时,如[10,10],一切都会正常运行。但是,一旦我将尺寸增加到更大的网络(例如[32,64,64,32]),卷曲就会失败,并显示以下错误: curle_couldnt_connect 经过数百次训练。它发生在POST函数中:

Json::Value POST(const std::string& route, const std::string& post_data)
{
    std::string url = "http://" + addr + route;
    if (verbose) printf("POST %s\n%s\n", url.c_str(), post_data.c_str());
    curl_easy_setopt(h.get(), CURLOPT_URL, url.c_str());
    curl_easy_setopt(h.get(), CURLOPT_PORT, port);
    std::string answer;
    curl_easy_setopt(h.get(), CURLOPT_WRITEDATA, &answer);
    curl_easy_setopt(h.get(), CURLOPT_POST, 1);
    curl_easy_setopt(h.get(), CURLOPT_POSTFIELDS, post_data.c_str());
    curl_easy_setopt(h.get(), CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)post_data.size());
    curl_easy_setopt(h.get(), CURLOPT_HTTPHEADER, headers.get());

    CURLcode r = curl_easy_perform(h.get());
    if (r)
        throw std::runtime_error(curl_error_buf.data());

    Json::Value j;
    throw_server_error_or_response_code(answer, j);
    return j;
}

被称为 Json::Value ans = client->POST("/v1/envs/" + instance_id + "/step/", act_json.toStyledString());,都可以在“ gym_binding.cpp”中找到。

奇怪的是,无论网络规模如何,通常在大约5000次成功连接后都会出现此问题。例如,我使用两个不同的网络维度来运行它,每次四次:当网络为[32,64,64,64,32]时,它发生在[5120, 5134, 7359, 7375]之后;当网络为[60,60]时,它会在[5134, 5167, 2678, 5272]次迭代后失败。我试图找到遇到此问题的最小网络,但找不到给定的网络。例如,有时[30,60]有效,而[30,30]无效。 我搜索了很多有关curl的信息,看来这是常规连接错误。但是,我的有点奇怪,因为它基于神经网络维度,并且有时(尽管并非总是如此)可以工作。我还监视了memorycpu的使用情况,发现任何不正常的情况。

另外,还有一个观察,我不得不重新启动服务器,然后它可以正常工作一天半,尽管之后它再次停止工作。 感谢您的帮助或评论。

0 个答案:

没有答案
相关问题