一般情况下,服务器客户端存在读写超时时间存在,因此某些情况需要设置一个超时时间

服务器程序设置超时时间:

#include "httplib.h"

#include <string>

using namespace httplib;

int main()

{

Server svr;

svr.set_read_timeout(5, 0); // 5 seconds

svr.set_write_timeout(5, 0); // 5 seconds

svr.set_idle_interval(0, 100000); // 100 milliseconds

svr.Get("/hi", [](const Request& req, Response& res)

{

res.set_content("Hello World!", "text/plain");

});

svr.Get("/stop", [&](const Request& req, Response& res)

{

svr.stop();

});

svr.listen("localhost", 1234);

return 0;

}


客户端程序设置:

#include <string>

using namespace httplib;

using namespace std;

int main()

{

httplib::Client cli("localhost", 1234);

cli.set_connection_timeout(0, 300000); // 300 milliseconds

cli.set_read_timeout(20, 0); // 20 seconds

cli.set_write_timeout(5, 0); // 5 seconds

if(auto res = cli.Get("/hi"))

{

if (res->status == 200)

{

std::cout << res->body << std::endl;

}

}

else

{

auto err = res.error();

}

return 0;

}


k8s python sdk 扩容 k8s pod升级

1.Deployment的升级示例:滚动升级busybox-deployment容器apiVersion: apps/v1 kind: Deployment metadata: name: busybox-deployment spec: replicas: 3 template: metadata: labels: app: busybox