网络配置系统前端改造与性能优化

网络配置系统简介

  • 网络配置系统是一个为美团点评公司的各类App提供的一个针对网络配置下发的管理系统
  • 目前已对接包括点评app,美团主app,美团外卖等10多款app,系统高峰qps超过2w(最近由于美团app问题,qps超过5w),每日调用量约10亿次

系统存在的问题

  • 在管理段对于任何app中的网络配置做修改都直接更新到redis中,服务端读取同一份redis,若配置出错,直接会导致线上问题
  • 配置内容中存在大量需要设定类型的配置,比如要求实际的值下发为 int, bool, list 等,新增配置导致代码修改
  • 无法提供线上测试功能,新增配置不易验证

系统数据流图--改造前

数据流-改造前

系统数据流图--改造后

数据流-改造后

页面改造前

页面改造前

页面改造后

页面优化后
内置类型支持
修改过程控制

数据结构-改造前

public class NTCache implements Serializable {

public NTCache() {}

@NTRecord(key = "nt.interval")
private int interval;              
@NTRecord(key = "nt.defaulttunnel")
private String defaulttunnel;     

private List<TunnelListItem> tunnelList;

@NTRecord(key = "nt.preblacklist.urlscheme", type = "urlscheme")
private List<PreBlackListItem> preblacklistUrlscheme;     
@NTRecord(key = "nt.preblacklist.contenttype", type = "contenttype")
private List<PreBlackListItem> preblacklistContenttype;   

private List<PreBlackListItem> preblacklist;   

@NTRecord(key = "whitehosts", area = NTArea.APPLOCAL)
private List<String> whitehosts;                          

@NTRecord(key = "specialList.wns", area = NTArea.APPLOCAL, type = "wns")
private List<SpecialListItem> specialListWNS;             
@NTRecord(key = "specialList.cip", area = NTArea.APPLOCAL, type = "cip")
private List<SpecialListItem> specialListCIP;             
@NTRecord(key = "specialList.http", area = NTArea.APPLOCAL, type = "http")
private List<SpecialListItem> specialListHTTP;            

private List<SpecialListItem> specialList;                

@NTRecord(key = "timeout.wns.2G", type = "2G")
private int timeoutWNS2G;               
@NTRecord(key = "timeout.wns.other", type = "other")
private int timeoutWNSOther;            
@NTRecord(key = "timeout.cip.2G", type = "2G")
private int timeoutCIP2G;               
@NTRecord(key = "timeout.cip.other", type = "other")
private int timeoutCIPOther;            
@NTRecord(key = "timeout.cip.udphold.2G", type = "2G")
private int timeoutCIPUdphold2G;        
@NTRecord(key = "timeout.cip.udphold.other", type = "other")
private int timeoutCIPUdpholdOther;     
@NTRecord(key = "timeout.cip.httphold.2G", type = "2G")
private int timeoutCIPHttphold2G;       
@NTRecord(key = "timeout.cip.httphold.2G.other", type = "other")
private int timeoutCIPHttpholdOther;    
@NTRecord(key = "timeout.http.2G", type = "2G")
private int timeoutHTTP2G;              
@NTRecord(key = "timeout.http.other", type = "other")
private int timeoutHTTPOther;           

private List<ExtraListItem> extraList;

}

数据结构-改造后

@Data
public class ConfigCache implements Serializable, Comparable<ConfigCache> {
    private String key;

    private Object value;  //数据已经过转型,为string/integer/boolean/list

    private String platform;  // all/android/ios

    private String sdkVersion;  

    private String beginVersion;  //app begin version

    private String endVersion;  // app end version

    private int orderNo;

    private List<CityRange> cityRanges;  
}

@Data
public class AppConfigCache implements Serializable {
    /**
     * 全局和特定APP
     */
    private List<ConfigCache> tunnel;

    /**
     * 全局和特定APP
     */
    private List<ConfigCache> others;

    /**
     * 全局filter, 特定APP specialList
     */
    private List<ConfigCache> filterOrSpecialList;

    /**
     * 全局timeout, 特定APP hosts
     */
    private List<ConfigCache> timeOutOrHosts;
}

@Getter
@Setter
public class AppConfigVersionCache implements Serializable {
    private AppConfigCache cache;

    private int version;
}

新旧数据分发过程对比

  • 旧的数据在内存中做了缓存,缓存结构如上述NTCache, 每次请求时都会使用反射对NTCache 做处理,同时对某些数据做类型转换,然后根据条件做匹配与排序之后得到配置数据
  • 新的数据处理过程,同样采用内存缓存,但数据已经过预处理(类型转换与排序),只需要做简单的匹配即得到配置数据

改造成果

  • 流程改造,加入配置内容的审核,可撤销未提交的修改
  • 前端改造,内置增加类型支持,新增配置轻松搞定,页面视觉优化
  • 系统单机压测 qps 超过15000(rpc service, 4核4G虚拟机, 99%请求延时在6ms以内)

作者感悟

  • 对于任何问题,选用合适的数据结构解决合适的问题,这样不但可以降低编写代码的复杂度,同时还可以降低代码的维护成本。
  • 程序= 数据结构 + 算法 , 俩手都要抓
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容