Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >源码走读rgw内置civetweb的参数初始化过程

源码走读rgw内置civetweb的参数初始化过程

作者头像
用户1260683
发布于 2018-01-31 03:58:18
发布于 2018-01-31 03:58:18
2K10
代码可运行
举报
运行总次数:0
代码可运行

1. 初始化civetweb时刻的参数传递

src/civetweb/civetweb.h

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/* Start web server.

   Parameters:
     callbacks: mg_callbacks structure with user-defined callbacks.
     options: NULL terminated list of option_name, option_value pairs that
              specify Civetweb configuration parameters.

   Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
      processing is required for these, signal handlers must be set up
      after calling mg_start().


   Example:
     const char *options[] = {
       "document_root", "/var/www",
       "listening_ports", "80,443s",
       NULL
     };
     struct mg_context *ctx = mg_start(&my_func, NULL, options);

   Refer to https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md
   for the list of valid option and their possible values.

   Return:
     web server context, or NULL on error. */
CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
                            void *user_data,
                            const char **configuration_options);

civetweb启动时的参数初始化由mg_start函数实现,注意configuration_options为具体的配置参数,配置参数的介绍可以参考https://github.com/bel2125/civetweb/blob/master/docs/UserManual.md

2. rgw中对civetweb启动时的参数初始化

src/rgw/rgw_civetweb_frontend.cc

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
int RGWMongooseFrontend::run() {
  char thread_pool_buf[32];
  snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d",
       (int)g_conf->rgw_thread_pool_size);
  string port_str;
  map<string, string> conf_map = conf->get_config_map();
  conf->get_val("port", "80", &port_str);
  conf_map.erase("port");
  conf_map["listening_ports"] = port_str; #默认端口设置
  set_conf_default(conf_map, "enable_keep_alive", "yes"); #默认开启了keepalive
  set_conf_default(conf_map, "num_threads", thread_pool_buf); #从rgw_thread_pool_size这个配置项中读取对应的并发数
  set_conf_default(conf_map, "decode_url", "no");

  // Set run_as_user. This will cause civetweb to invoke setuid() and setgid()
  // based on pw_uid and pw_gid obtained from pw_name.
  string uid_string = g_ceph_context->get_set_uid_string();
  if (!uid_string.empty()) {
    conf_map.erase("run_as_user");
    conf_map["run_as_user"] = uid_string;
  }

  const char *options[conf_map.size() * 2 + 1];
  int i = 0;
  for (map<string, string>::iterator iter = conf_map.begin();
       iter != conf_map.end(); ++iter) {
    options[i] = iter->first.c_str();
    options[i + 1] = iter->second.c_str();
    dout(20)<< "civetweb config: " << options[i] << ": "
        << (options[i + 1] ? options[i + 1] : "<null>") << dendl;
    i += 2;
  }
  options[i] = NULL;

  struct mg_callbacks cb;
  memset((void *)&cb, 0, sizeof(cb));
  cb.begin_request = civetweb_callback;
  cb.log_message = rgw_civetweb_log_callback;
  cb.log_access = rgw_civetweb_log_access_callback;
  ctx = mg_start(&cb, &env, (const char **)&options);#启动civetweb

  if (!ctx) {
    return -EIO;
  }

  return 0;
} /* RGWMongooseFrontend::run */

通过RGWMongooseFrontend的run方法,实现了civetweb的启动参数初始化。

3. 几个比较有用的参数介绍

throttle

Limit download speed for clients. throttle is a comma-separated list of key=value pairs, where key could be:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
*                   limit speed for all connections
x.x.x.x/mask        limit speed for specified subnet
uri_prefix_pattern  limit speed for given URIs

The value is a floating-point number of bytes per second, optionally followed by a k or m character, meaning kilobytes and megabytes respectively. A limit of 0 means unlimited rate. The last matching rule wins. Examples:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
*=1k,10.0.0.0/8=0   limit all accesses to 1 kilobyte per second,
                    but give connections the from 10.0.0.0/8 subnet
                    unlimited speed

/downloads/=5k      limit accesses to all URIs in `/downloads/` to
                    5 kilobytes per second. All other accesses are unlimited

可以实现针对不同的subnet和URL设置下载速度,在需要限速的场景下比较有用

access_control_list

An Access Control List (ACL) allows restrictions to be put on the list of IP addresses which have access to the web server. In the case of the Civetweb web server, the ACL is a comma separated list of IP subnets, where each subnet is pre-pended by either a - or a + sign. A plus sign means allow, where a minus sign means deny. If a subnet mask is omitted, such as -1.2.3.4, this means to deny only that single IP address.

Subnet masks may vary from 0 to 32, inclusive. The default setting is to allow all accesses. On each request the full list is traversed, and the last match wins. Examples:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-0.0.0.0/0,+192.168/16    deny all accesses, only allow 192.168/16 subnet

这个应该都比较熟了,ACL控制哪些subnet或者host可以访问

num_threads

Number of worker threads. Civetweb handles each incoming connection in a separate thread. Therefore, the value of this option is effectively the number of concurrent HTTP connections Civetweb can handle.

控制单个civetweb实例的最大并发数

allow_sendfile_call

This option can be used to enable or disable the use of the Linux sendfile system call. It is only available for Linux systems and only affecting HTTP (not HTTPS) connections if throttle is not enabled. While using the sendfile call will lead to a performance boost for HTTP connections, this call may be broken for some file systems and some operating system versions.

援引一段对sendfile特性的描述 sendfile() copies data between one file descriptor and another.Because this copying is done within the kernel, sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data to and from user space. 启动该特性以后部分数据复制操作将在内核内部完成,能够减少上下文切换带来的性能损耗。

http://man7.org/linux/man-pages/man2/sendfile.2.html

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-04-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Ceph对象存储方案 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
1 条评论
热度
最新
不错。刚好遇到rgw主动关闭长连接的情况。线上试一下。再看看效果。现在是c++小白。有关于如何使用Clion debug ceph代码的文章吗?
不错。刚好遇到rgw主动关闭长连接的情况。线上试一下。再看看效果。现在是c++小白。有关于如何使用Clion debug ceph代码的文章吗?
回复回复点赞举报
推荐阅读
编辑精选文章
换一批
源码阅读再来一发:解读RGW中request的处理流程
请求处理流程图 以civetweb为例 1. rgw_main.cc为整个radosgw服务的入口,main()函数中根据在ceph.conf的rgw frontends参数设置来选择不同的前端
用户1260683
2018/01/31
3K0
源码阅读再来一发:解读RGW中request的处理流程
Ceph RGW整体结构,最全干货在这!
小新 职场新人,存储小白 立志成为职场老鸟,存储专家; 影视迷,东野迷。   友情提醒:以下内容有点干,请自备快乐水~ 一、前言 Ceph中的对象存储网关RadosGW和Ceph RBD以及CephFS一样,构建在librados之上,主要提供的命令工具有如下: radosgw : 用来启动radosgw服务,并且提供restful的访问方式,也是下文讨论的对象 radosgw-admin : 用来提供admin的管理服务,如创建user等 另还有radosgw-es、radosgw-token和ra
腾讯云TStack
2020/05/20
9.4K0
ceph S3_ceph minio
参考资料: https://www.cnblogs.com/ytc6/p/7388654.html http://docs.ceph.com/docs/kraken/start/ https://blog.csdn.net/changtao381/article/details/48015623 https://blog.csdn.net/litianze99/article/details/48438877
全栈程序员站长
2022/09/27
6430
ceph S3_ceph minio
Linux 性能测试工具 sysbench 的安装与简单使用
sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。 sysbench 支持以下几种测试模式 :
耕耘实录
2019/07/04
7.3K0
impala 启动参数1
impalad: Warning: SetUsageMessage() never called
jasong
2022/08/29
1.6K0
docker-compose 安装部署 redis
配置准备 docker 和 docker-compose 安装 http://xieboke.net/article/341/ 创建 redis主目录 mkdir /usr/local/redis cd /usr/local/redis 创建 redis 的子目录 mkdir -p /usr/local/redis/data /usr/local/redis/logs /usr/local/redis/conf chmod -R 777 /usr/local/redis/data* chmod -R 777
卓越笔记
2023/02/18
2.9K0
docker-compose 安装部署 redis
>>技术应用:clickhouse 帮助命令一览表
常见的列式数据库有: Vertica、 Paraccel (Actian Matrix,Amazon Redshift)、 Sybase IQ、 Exasol、 Infobright、 InfiniDB、 MonetDB (VectorWise, Actian Vector)、 LucidDB、 SAP HANA、 Google Dremel、 Google PowerDrill、 Druid、 kdb+。下面是clickhouse命令的帮助文档,当前CK的版本为:ClickHouse server /client version 22.3.1.1,其他版本酌情参考。
艾特
2023/10/10
1.2K0
Impala 启动参数2
Flags from /data/impala/be/src/runtime/io/data-cache.cc:
jasong
2022/08/29
1.1K0
docker安装服务
2、docker run --name mynginx -d nginx: 运行nginx实例
爱撒谎的男孩
2019/12/31
5790
Docker安装tomcat, mysql,redis(单机版)
即可通过 http://IP:8080 访问,最新版的tomcat10需要把 webapps.dist 目录换成webapps 才能访问主页
鱼找水需要时间
2023/02/16
1.5K0
Docker安装tomcat, mysql,redis(单机版)
【docker专题_06】docker安装redis
3.下载redis.conf文件(或者用我下面给出的),并存放在/root/docker/redis
夏之以寒
2024/03/04
1840
DAOS引擎启动流程-源码分析_模块初始化_如VOS等
执行:daos_server start, server通过golang调用engine的c
晓兵
2023/06/01
1K0
DAOS引擎启动流程-源码分析_模块初始化_如VOS等
Docker常用软件安装之Redis
  我们首先需要在root/myredis/conf/redis.conf目录下创建redis.conf配置文件。
用户4919348
2019/12/31
1.1K0
nginx源码阅读(2)master和worker进程创建流程
ngx_uint_t log_use_stderr; /* unsigned log_use_stderr:1; */
golangLeetcode
2022/08/02
4270
sqlmap 源码分析(二)初始化
sqlmap是web狗永远也绕不过去的神器,为了能自由的使用sqlmap,阅读源码还是有必要的…
LoRexxar
2023/02/21
7180
[源码解析] PyTorch分布式(6) -------- DistributedDataParallel -- 初始化&store
本文是 PyTorch 分布式系列的第六篇, 介绍 DistributedDataParallel 所依赖的初始化方法和Store这两个概念。
罗西的思考
2021/11/22
1.3K0
[源码解析] PyTorch分布式(6) -------- DistributedDataParallel -- 初始化&store
ceph-对象存储
作为文件系统的磁盘,操作系统不能直接访问对象存储。相反,它只能通过应用程序级别的API访问。ceph是一种分布式对象存储系统,通过ceph对象网关提供对象存储接口,也称为RADOS网关(RGW)接口,它构建在ceph RADOS层之上。RGW使用librgw(RADOS Gateway library)和librados,允许应用程序与ceph对象存储建立连接。RGW为应用程序提供了一个RESTful S3/swift兼容的接口,用于在ceph集群中以对象的形式存储数据。ceph还支持多租户对象存储,可以通过RESTful API访问。此外,RGW还支持ceph管理API,可以使用本机API调用来管理ceph存储集群。
yuezhimi
2020/09/30
3.9K0
初试 Ceph 存储之块设备、文件系统、对象存储
哎_小羊
2018/01/02
6.5K0
初试 Ceph 存储之块设备、文件系统、对象存储
Elasticsearch源码一之服务启动初始化
构造方法主要预设命令行参数解析项,将这些信息预先设置到option变量中。同时会调用父类的构造方法,会传入一个线程,这个线程就是下文中会提到的父类中的beforeMain线程。
山行AI
2020/03/11
7960
Elasticsearch源码一之服务启动初始化
Docker-compose封装mysql并初始化数据以及redis
现有一台服务器,需要部署mysql和redis。其中mysql容器,需要在第一次启动时,执行sql文件。
py3study
2020/04/24
5.5K0
相关推荐
源码阅读再来一发:解读RGW中request的处理流程
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验