twemproxy源码分析之五:zero copy

本文详细解析了msg数据结构的组成及其在不同场景下的应用,包括客户端、服务器端以及消息发送队列之间的交互。通过阐述其内部结构如ID、路由索引、消息类型等关键属性,揭示了其在消息传递过程中的重要角色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先给出msg的数据结构:
 
truct msg {
    TAILQ_ENTRY(msg)     c_tqe;          
    TAILQ_ENTRY(msg)     s_tqe;          
    TAILQ_ENTRY(msg)     m_tqe;          

    uint64_t             id;              
    int                  route_idx;      
    struct msg           *peer;          
    struct conn          *owner;          

    struct rbnode        tmo_rbe;        

    struct mhdr          mhdr;            
    uint32_t             mlen;            

    int                  state;          
    uint8_t              *pos;            
    uint8_t              *token;          

    msg_parse_t          parser;          
    msg_parse_result_t   result;          

    mbuf_copy_t          pre_splitcopy;  
    msg_post_splitcopy_t post_splitcopy;  
    msg_coalesce_t       pre_coalesce;    
    msg_coalesce_t       post_coalesce;  

    msg_type_t           type;            

    uint8_t              *key_start;      
    uint8_t              *key_end;        

    uint32_t             vlen;            
    uint8_t              *end;            

    uint8_t              *narg_start;    
    uint8_t              *narg_end;      
    uint32_t             narg;            
    uint32_t             rnarg;          
    uint32_t             rlen;            
    uint32_t             integer;        

    struct msg           *frag_owner;    
    uint32_t             nfrag;          
    uint64_t             frag_id;        

    err_t                err;            
    unsigned             error:1;        
    unsigned             ferror:1;        
    unsigned             request:1;      
    unsigned             quit:1;          
    unsigned             noreply:1;      
    unsigned             done:1;          
    unsigned             fdone:1;        
    unsigned             first_fragment:1;
    unsigned             last_fragment:1;
    unsigned             swallow:1;      
    unsigned             redis:1;        
 


看这三个成员   
    TAILQ_ENTRY(msg)     c_tqe;          
    TAILQ_ENTRY(msg)     s_tqe;          
    TAILQ_ENTRY(msg)     m_tqe;          
c_tqe是用来插入到client类型的conn中的输入或者输出队列中
s_tqe是用来插入到server类型的conn(即连接后端redis server的conn)中的输入或者输出队列中
m_tqe是用来插入到发送对列(一个发送队列对应一个远端或是client或是redisinstance)中的输入或者输出队列中
具体的插入删除过程见上一篇。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值