问题:
后台有很多机器,每个请求过来后,会根据request header中的host来选择对应的后端(通过balancer_by_lua_file实现)
host与后端的队列关系如下:站点大概有10W个
{
'website1.com':
{
{
'host': '127.0.0.1',
'port': 8000
},
{
'host': '127.0.0.2',
'port': 8001
},
...
}
}
{
'website2.com':
{
{
'host': '127.0.0.3',
'port': 8011
},
{
'host': '127.0.0.4',
'port': 8012
},
...
}
}
...
我现在的处理方案是采用ngx.shared.dict存host与后端的对应关系,由于shared.dict的value不能为table,所以将后端机器先用json.encode,等处理的时候再用json.decode解码,今天压测时发现1.7W QPS时cpu利用率就有60%,通过火焰图发现json的encode,decode占了很长的时间。
dict = {
'website1.com': 'xxxxx',
'website2.com': 'xxxxx'
...
}
请问,json占cpu高有啥优化方案吗?或是不采用shared.dict,有别的替代方案没?