首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >源码走读rgw内置civetweb的参数初始化过程

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

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

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

src/civetweb/civetweb.h

代码语言:javascript
代码运行次数:0
运行
复制
/* 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
运行
复制
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
运行
复制
*                   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
运行
复制
*=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
运行
复制
-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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
PHP-MySQL基本操作
PHP-MySQL基本操作 1 <?php 2 3 // 1.防止页面中文乱码 4 header("content-type:text/html;charset=utf-8");
ProsperLee
2019/03/19
1.1K0
MySQL修改字段类型、字段名字、字段长度、字段小数点长度。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139788.html原文链接:https://javaforall.cn
全栈程序员站长
2022/09/03
14.3K0
MySQL修改字段类型、字段名字、字段长度、字段小数点长度。
MySQL数据库SQL脚本DDL(数据定义语言)数据表操作
今天的命令操作是基于某个数据库而言的,也就是说要先进入到某个数据库,使用命令use 数据库名称,例如 use ljydb; 1.创建数据表 Create table 表名(字段名 字段类型 约束类型) 按照以上格式创建数据表,注意一定要使用英文输入法下的符号,每个关键词后有一个空格。 举例创建用户表ljy_userinfo Create table ljy_userinfo ( userid int(11), username varchar(20), password varchar(20), Create_time datetime ) 以上代码创建了用户信息表ljy_userinfo,字段分别为用户编号,用户名称,密码,创建时间。 创建完成后使用show tables;查看数据库中的表 我们也可以使用命令desc table 表名称 来查看创建的数据表的列。
刘金玉编程
2021/02/02
1.3K0
MySQL表的操作『增删改查』
当前创建的 数据库 testForTable 字符集和校验集分别为 utf8 和 utf8_general_ci,这是由配置文件中的默认编码集决定的
北 海
2023/11/25
4170
MySQL表的操作『增删改查』
Mysql学习——MySQL数据结构修改(2)
1.添加表字段 语法:  ALTER TABLE 表名 ADD 字段名 数据类型; 例如:  ALTER TABLE User ADD modifyTime VARCHAR(100); 2.修改字段类型 语法: ALTER TABLE 表名 MODIFY 要修改的字段 修改后的数据类型; 例如: ALTER TABLE User MODIFY modifyTime Int; 3.修改字段名 CHANGE 后面跟着要修改的字段以及修改后的字段 语法: ALTER TABLE 表名 CHANGE 要修
十分钟空间
2022/08/17
1.3K0
MySQL从安装到使用
Columns 列;Indexes 索引;Views 视图;Events 事件;Fields 字段;
慕白
2018/08/03
7550
mysql修改、增加、删除字段名等命令
星辰sea
2023/06/10
2K0
《MySQL入门很轻松》第4章:数据表的创建修改删除
数据表属于数据库,在创建数据库之前,应该使用use <数据库名称>指定操作是在哪个数据库中进行。
炒香菇的书呆子
2022/02/15
7010
《MySQL入门很轻松》第4章:数据表的创建修改删除
MySQL - 简单笔记
创建数据库 create database if not exists mydb; 查看mySQL服务器中所有数据库 show databases; 示例: mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | keai | | kenvie | | mydb
kenvie
2022/01/20
3250
初识MySQL · 表的操作
上一篇文章我们介绍了库的操作,而在我们学习MySQL的第一篇文章就提及了,使用MySQL的时候,先是创建数据库,然后是创建表,表和数据库的重要关系其实是对等的,所以相关的操作,对于增删查改也是同理。
_lazy
2024/10/23
1770
MySQL数据库学习·数据表的创建,查看,修改
提示我写错了,仔细看一看,原来是auto_increment被我少写了一个e。
花狗Fdog
2020/10/28
5.7K0
MySQL数据库学习·数据表的创建,查看,修改
查询 MySQL 字段注释的 5 种方法!
很多场景下,我们需要查看 MySQL 中表注释,或者是某张表下所有字段的注释,所以本文就来盘点和对比一下查询注释的几种方式。
磊哥
2022/05/09
5.9K0
查询 MySQL 字段注释的 5 种方法!
Oracle增加修改删除字段/主键
总结: 1、当字段没有数据或者要修改的新类型和原类型兼容时,可以直接modify修改。 2、当字段有数据并用要修改的新类型和原类型不兼容时,要间接新建字段来转移。
小小工匠
2021/08/16
2.4K0
MySQL 修改字段类型和字段长度
格式:alter table 表名 modify column 字段名 类型(长度);
全栈程序员站长
2022/08/18
11.6K0
【Mysql】耗时7200秒整理的mysql笔记!常用API汇总!包教包会!
a. 找到MySql解压好的文件夹的根目录,在根目录下创建文件 my.ini(后缀为.ini)
LonelySnowman
2022/12/05
1.5K0
MySql笔记
又很久没有写博客了 这篇笔记是边学边记的 当时比较仓促 所以有的地方可能会比较乱 但是大概的方法写的还是比较清楚了 等有时间回头再好好整理一下这篇文章。
用户2700375
2022/06/09
7340
MySql笔记
【MySQL】DDL的表操作详解:创建&查询&修改&删除(记得3点加上连接)
YY的秘密代码小屋
2024/03/22
8460
【MySQL】DDL的表操作详解:创建&查询&修改&删除(记得3点加上连接)
MySQL修改字段名、修改字段类型
修改字段 类型、名、注释、类型长度、默认值 ALTER TABLE 表名 MODIFY [COLUMN] 字段名 新类型 新类型长度 新默认值 新注释; -- COLUMN关键字可以省略不写 -- 能修改字段类型、类型长度、默认值、注释 alter table table1 modify column column1 decimal(10,1) DEFAULT NULL COMMENT '注释'; -- 能修改字段类型、类型长度、默认值、注释 alter table table
JavaEdge
2021/03/04
33.7K0
MySQL修改字段名、修改字段类型
创建和管理表
SHOW TABLES FROM 数据库名 直接写SHOW TABLES,查看的是当前使用数据库下的表
code-child
2023/05/30
7080
创建和管理表
MySQL的库表详细操作
  关于库的内容,咱们就说这些吧,哈哈,有点少是吧,不是咱们的重点,来看下面的表操作~~~
changxin7
2022/05/06
1.1K0
MySQL的库表详细操作
相关推荐
PHP-MySQL基本操作
更多 >
目录
  • 2. rgw中对civetweb启动时的参数初始化
  • 3. 几个比较有用的参数介绍
    • throttle
    • access_control_list
    • num_threads
    • allow_sendfile_call
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档