from integer makes pointer_Nginx编译时error: assignment makes pointer from integer without a cast处理...

Nginx升级-从nginx-1.8.1到nginx-1.12.2

原来是源码编译安装的

升级过程中,make时报错

……

c/http -I src/http/modules \

-o objs/src/http/modules/ngx_http_stub_status_module.o \

src/http/modules/ngx_http_stub_status_module.c

cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I /data/pcre-8.37 -I objs -I src/http -I src/http/modules \

-o objs/addon/nginx-sticky-module-1.25/ngx_http_sticky_module.o \

/data/nginx-sticky-module-1.25/ngx_http_sticky_module.c

cc1: warnings being treated as errors

/data/nginx-sticky-module-1.25/ngx_http_sticky_module.c: In function ‘ngx_http_get_sticky_peer’:

/data/nginx-sticky-module-1.25/ngx_http_sticky_module.c:340: error: assignment makes pointer from integer without a cast

make[1]: *** [objs/addon/nginx-sticky-module-1.25/ngx_http_sticky_module.o] Error 1

make[1]: Leaving directory `/data/nginx-1.12.2'

make: *** [build] Error 2

[root@test01 nginx-1.12.2]#

参考网上资料进行文件修改后成功解决

第一次修改:

ngx_http_sticky_misc.c 的281行修改如下

digest->len = ngx_sock_ntop(in, digest->data, len, 1);

改后

digest->len = ngx_sock_ntop(in, sizeof(struct sockaddr_in), digest->data, len, 1);

ngx_http_sticky_module.c文件也进行修改

第6行添加:

#include

第340行左右修改(iphp->rrp.current = iphp->selected_peer;)为:

if (peer && selected_peer >= 0) {

ngx_log_debug(NGX_LOG_DEBUG_HTTP, pc->log, 0, "[sticky/get_sticky_peer] peer found at index %i", selected_peer);

#if defined(nginx_version) && nginx_version >= 1009000

iphp->rrp.current = peer;

#else

iphp->rrp.current = iphp->selected_peer;

#endif

但是再次编译又有新的报错:

rc/http -I src/http/modules \

-o objs/addon/nginx-sticky-module-1.25/ngx_http_sticky_misc.o \

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c: In function ‘ngx_http_sticky_misc_md5’:

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:152: error: ‘MD5_DIGEST_LENGTH’ undeclared (first use in this function)

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:152: error: (Each undeclared identifier is reported only once

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:152: error: for each function it appears in.)

cc1: warnings being treated as errors

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:152: error: unused variable ‘hash’

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c: In function ‘ngx_http_sticky_misc_hmac_md5’:

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:189: error: ‘MD5_DIGEST_LENGTH’ undeclared (first use in this function)

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:190: error: ‘MD5_CBLOCK’ undeclared (first use in this function)

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:190: error: unused variable ‘k’

/data/nginx-sticky-module-1.25/ngx_http_sticky_misc.c:189: error: unused variable ‘hash’

make[1]: *** [objs/addon/nginx-sticky-module-1.25/ngx_http_sticky_misc.o] Error 1

make[1]: Leaving directory `/data/nginx-1.12.2'

make: *** [build] Error 2

[root@test01 nginx-1.12.2]#

第二次修改:

ngx_http_sticky_misc.c中新增2个模块 和

#include

#include

#include

#include

#include

#include

#include

#include

#include "ngx_http_sticky_misc.h"

之后再重新编译就不会出错了。

参考:

后续文章将主要在公众号“技术进阶与实战”(WXID:HelloException)发布,欢迎关注

### 高并发场景中的内存池设计与优化 #### 设计原则 在高并发环境中,内存池通过预先分配大块内存来减少频繁的系统调用开销并控制内存碎片化。这种机制显著提高了多线程应用下的内存管理和释放速度[^1]。 #### 实现方式 为了适应不同应用场景的需求,内存池可以根据具体业务逻辑定制其内部结构: - **固定大小对象池**:适用于所有对象具有相同尺寸的情况。这种方式简化了内存管理流程,因为每次只需处理预定义长度的数据单元即可。 - **可变大小对象池**:当应用程序涉及多种类型的对象时,则需构建支持任意尺寸数据存储的能力。此时可通过链表或其他高效查找算法维护多个分区,每个分区负责特定范围内的对象实例创建和销毁操作。 ```cpp class MemoryPool { public: void* allocate(size_t size); bool deallocate(void *ptr); private: std::vector<Chunk*> chunks_; // 存储已划分好的内存片段列表 }; ``` #### 优化策略 针对高并发特性进一步改进内存池表现的方法包括但不限于以下几个方面: - **无锁编程模型**:利用原子指令代替传统互斥锁,在保证线程安全的同时极大程度降低了同步成本。对于某些热点路径还可以考虑引入读写分离机制以提升整体吞吐量。 - **本地缓存层**:为每一个工作线程配备独立的小型缓冲区用于临时存放待分配/回收的对象地址,以此减少全局资源竞争带来的延迟影响。 - **快速失败检测**:一旦发现当前节点无法满足新的内存请求就立即返回错误码给上游模块而不是长时间等待其他组件完成相应动作;这有助于及时止损并将压力分散到整个集群当中去。 - **自适应调整参数**:依据实时监控指标动态调节初始容量、增长因子等配置项,确保即使面对突发流量冲击也能保持稳定的服务质量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值