当前位置: 首页 > news >正文

学做婴儿衣服的网站北京网站建设方案哪家好

学做婴儿衣服的网站,北京网站建设方案哪家好,企业网站新闻如何建设,企业介绍模板范文应用场景 有时为了保证可用性,需要同时访问两路服务,哪个先返回就取哪个。在brpc中,这有多种做法,根据server是否挂在同一个命名服务内有所区别。 当后端server可以挂在一个命名服务内时 Channel开启backup request。这个Channel会先向其中一个server发送请求,如果在Ch…应用场景 有时为了保证可用性,需要同时访问两路服务,哪个先返回就取哪个。在brpc中,这有多种做法,根据server是否挂在同一个命名服务内有所区别。 当后端server可以挂在一个命名服务内时 Channel开启backup request。这个Channel会先向其中一个server发送请求,如果在ChannelOptions.backup_request_ms后还没回来,再向另一个server发送。之后哪个先回来就取哪个。在设置了合理的backup_request_ms后,大部分时候只会发一个请求,对后端服务只有一倍压力。 #include gflags/gflags.h #include butil/logging.h #include butil/time.h #include brpc/channel.h #include "echo.pb.h"DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options.proto"); DEFINE_string(connection_type, "", "Connection type. Available values: single, pooled, short"); DEFINE_string(server, "0.0.0.0:8000", "IP Address of server"); DEFINE_string(load_balancer, "", "The algorithm for load balancing"); DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds"); DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); DEFINE_int32(backup_request_ms, 2, "Timeout for sending backup request");int main(int argc, char* argv[]) {// Parse gflags. We recommend you to use gflags as well.GFLAGS_NS::ParseCommandLineFlags(argc, argv, true);// A Channel represents a communication line to a Server. Notice that // Channel is thread-safe and can be shared by all threads in your program.brpc::Channel channel;// Initialize the channel, NULL means using default options.brpc::ChannelOptions options;options.protocol = FLAGS_protocol;options.connection_type = FLAGS_connection_type;options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;options.max_retry = FLAGS_max_retry;// 设置backup_request_ms参数,在超时后会自动向另外一个server重发请求,与首次请求一起,哪个先返回用哪个options.backup_request_ms = FLAGS_backup_request_ms;if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), options) != 0) {LOG(ERROR) "Fail to initialize channel";return -1;}// Normally, you should not call a Channel directly, but instead construct// a stub Service wrapping it. stub can be shared by all threads as well.example::EchoService_Stub stub(channel);// Send a request and wait for the response every 1 second.int counter = 0;while (!brpc::IsAskedToQuit()) {// We will receive response synchronously, safe to put variables// on stack.example::EchoRequest request;example::EchoResponse response;brpc::Controller cntl;request.set_index(++counter);// Because `done'(last parameter) is NULL, this function waits until// the response comes back or error occurs(including timedout).stub.Echo(cntl, request, response, NULL);if (!cntl.Failed()) {LOG(INFO) "Received response[index=" response.index() "] from " cntl.remote_side() " to " cntl.local_side() " latency=" cntl.latency_us() "us";} else {LOG(WARNING) cntl.ErrorText();}sleep(1);}LOG(INFO) "EchoClient is going to quit";return 0; }backup_request_ms推荐值 backup_request_ms=2ms可以大约覆盖95.5%的请求,选择backup_request_ms=10ms则可以覆盖99.99%的请求。 当后端server不能挂在一个命名服务内时 方案一、使用SelectiveChannel: 建立一个开启backup request的SelectiveChannel,其中包含两个sub channel。访问这个SelectiveChannel和上面的情况类似,会先访问一个sub channel,如果在ChannelOptions.backup_request_ms后没返回,再访问另一个sub channel。如果一个sub channel对应一个集群,这个方法就是在两个集群间做互备。 #include gflags/gflags.h #include bthread/bthread.h #include butil/logging.h #include brpc/selective_channel.h #include brpc/parallel_channel.h #include "echo.pb.h"DEFINE_int32(thread_num, 50, "Number of threads to send requests"); DEFINE_bool(use_bthread, false, "Use bthread to send requests"); DEFINE_int32(attachment_size, 0, "Carry so many byte attachment along with requests"); DEFINE_int32(request_size, 16, "Bytes of each request"); DEFINE_string(connection_type, "", "Connection type. Available values: single, pooled, short"); DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options.proto"); DEFINE_string(starting_server, "0.0.0.0:8114", "IP Address of the first server, port of i-th server is `first-port + i'"); DEFINE_string(load_balancer, "rr", "Name of load balancer"); DEFINE_int32
http://www.hkea.cn/news/14546295/

相关文章:

  • ui外包网站长沙竞价网站建设价格
  • 桂林网站制作哪家好怎样做旅游网站设计
  • 手机网站制作解决方案怎么建个废品网站
  • 一个新的网站怎么做SEO优化seo门户网
  • 响应式网站是什么情况南宁市网站建设价格
  • 联系人网站设计上海公司注销需要多少钱费用?
  • 做网站的公司介绍微信分销网站建设多少钱
  • 网站开发亿玛酷适合5wordpress使用密码
  • 网站模板套用如何创建企业邮箱
  • 在线做网站黄农村自建房设计图纸
  • 深圳市做网站建设手机管理wordpress站
  • 珠海网站系统建设自学网站制作教程
  • 源码网站程序wordpress多个边栏
  • 贴吧做网站建设网站运营收入
  • 做微信头图的网站wordpress标签生成图片
  • 做的比较好的美食网站vs做的网站源代码
  • 建设营销型网站广州黄骅港船舶动态
  • 织梦cms可以做淘宝客网站么wordpress 代码压缩
  • 洛阳市政建设集团网站教师可以做网站吗
  • wordpress企业站爱主题网站域名需要购买吗
  • dw怎么做网站后台17网站一起做网店2018
  • 北京产品网站设计哪家专业j2ee大型网站开发框架
  • flash网站as工业设计就业前景
  • 做百度推广需要有网站吗个人网站设计首页界面
  • 做网站需要什么源码wordpress主题破解网站
  • 网站开发形式药品彩页设计
  • 网站建设怎么做账会计哪个网站可以直接做ppt
  • 手机网站百度关键词排名查询湖北医院网站建设
  • 网站建设毕业设计的分类号网页制作素材去哪找
  • 怎么上传自己做的网站陈木胜妻子