1. 修复命中缓存策略后,缓存上传的处理逻辑
2. 支持新版本的FieldStat的Histogram输出
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <MESA/field_stat2.h>
|
||||
|
||||
|
||||
const char* FP_HISTOGRAM_BINS="10,50,100,500";
|
||||
const char* FP_HISTOGRAM_BINS="0.5,0.8,0.9,0.95";
|
||||
|
||||
struct future_promise_instance
|
||||
{
|
||||
@@ -110,7 +110,7 @@ static long field_get_set_cb(void * data, const uchar * key, uint size, void * u
|
||||
{
|
||||
field_id=(int*)malloc(sizeof(int)*2);
|
||||
snprintf(buff,sizeof(buff),"%s(ms)",(char*)key);
|
||||
field_id[0]=FS_register(args->fs_handle, FS_STYLE_HISTOGRAM, FS_CALC_CURRENT, buff);
|
||||
field_id[0]=FS_register_histogram(args->fs_handle, FS_CALC_SPEED, buff, 1, 5*1000, 2);//1ms~5s
|
||||
args->fsid_latency=field_id[0];
|
||||
snprintf(buff,sizeof(buff),"%s%s",(char*)key,fail_str);
|
||||
field_id[1]=FS_register(args->fs_handle, FS_STYLE_FIELD, FS_CALC_SPEED,buff);
|
||||
|
||||
@@ -440,7 +440,6 @@ struct pangu_http_ctx
|
||||
size_t datalen, unsigned int thread_id, struct pangu_http_ctx* ctx);
|
||||
|
||||
enum cache_pending_result pending_result;
|
||||
enum cache_query_status cache_query_status;
|
||||
struct future *f_cache_pending, *f_cache_query;
|
||||
struct tfe_http_session * ref_session;
|
||||
struct tfe_http_half* cache_revalidate_req;
|
||||
@@ -1085,16 +1084,16 @@ static void cache_query_on_succ(future_result_t * result, void * user)
|
||||
break;
|
||||
case CACHE_QUERY_RESULT_END:
|
||||
assert(ctx->cached_response!=NULL);
|
||||
ctx->cache_query_status=WEB_CACHE_HIT;
|
||||
tfe_http_half_write_body_end(ctx->cached_response);
|
||||
//ownership has been transferred to http session, set to NULL.
|
||||
//ownership has been transferred to http session, set to NULL.
|
||||
ctx->pending_result=PENDING_RESULT_HIT;
|
||||
ctx->cached_response=NULL;
|
||||
assert(ctx->cache_result_actual_sz==ctx->cache_result_declared_sz);
|
||||
future_destroy(ctx->f_cache_query);
|
||||
ctx->f_cache_query=NULL;
|
||||
break;
|
||||
case CACHE_QUERY_RESULT_MISS:
|
||||
ctx->cache_query_status=WEB_CACHE_MISS;
|
||||
ctx->pending_result=PENDING_RESULT_MISS;
|
||||
ctx->resumed_cb=dummy_resume;
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
future_destroy(ctx->f_cache_query);
|
||||
@@ -1110,7 +1109,6 @@ static void cache_query_on_fail(enum e_future_error err, const char * what, void
|
||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||
future_destroy(ctx->f_cache_query);
|
||||
ctx->f_cache_query=NULL;
|
||||
ctx->cache_query_status=WEB_CACHE_MISS;
|
||||
if(!ctx->cached_response)
|
||||
{
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
@@ -1121,7 +1119,7 @@ static void cache_query_on_fail(enum e_future_error err, const char * what, void
|
||||
tfe_http_half_write_body_end(ctx->cached_response);
|
||||
ctx->cached_response=NULL;
|
||||
}
|
||||
|
||||
ctx->pending_result=PENDING_RESULT_MISS;
|
||||
printf("cache query failed: %s %s\n", ctx->ref_session->req->req_spec.url, what);
|
||||
}
|
||||
static void cache_pending_on_succ(future_result_t * result, void * user)
|
||||
@@ -1346,7 +1344,8 @@ void pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_
|
||||
}
|
||||
}
|
||||
|
||||
if(tfe_http_in_response(events)&& ctx->pending_result==PENDING_RESULT_MISS)
|
||||
if(tfe_http_in_response(events)
|
||||
&& (ctx->pending_result==PENDING_RESULT_MISS||ctx->pending_result==PENDING_RESULT_ALLOWED))
|
||||
{
|
||||
cache_update(session, events, body_frag, frag_size, thread_id, ctx);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ void cache_stat_init(struct cache_handle* cache)
|
||||
{
|
||||
const char* fieldstat_output="./cache.fieldstat";
|
||||
const char* app_name="tango_cache";
|
||||
const char* obj_size_bins_KB="10,100,1000,10000";
|
||||
const char* obj_size_bins_KB="0.5,0.8,0.9,0.95";
|
||||
|
||||
int value=0, i=0;
|
||||
screen_stat_handle_t fs_handle=NULL;
|
||||
@@ -238,7 +238,14 @@ void cache_stat_init(struct cache_handle* cache)
|
||||
|
||||
for(i=0;i<__CACHE_STAT_MAX;i++)
|
||||
{
|
||||
cache->fs_id[i]=FS_register(cache->fs_handle, spec[i].style, spec[i].calc_type, spec[i].name);
|
||||
if(spec[i].style==FS_STYLE_HISTOGRAM)
|
||||
{
|
||||
cache->fs_id[i]=FS_register_histogram(cache->fs_handle, spec[i].calc_type, spec[i].name,1,10*1024*1024,2);
|
||||
}
|
||||
else
|
||||
{
|
||||
cache->fs_id[i]=FS_register(cache->fs_handle, spec[i].style, spec[i].calc_type, spec[i].name);
|
||||
}
|
||||
}
|
||||
// value=cache->fs_id[STAT_CACHE_QUERY_HIT];
|
||||
// FS_set_para(cache->fs_handle, ID_INVISBLE, &value, sizeof(value));
|
||||
@@ -492,7 +499,6 @@ void cache_param_new(int idx, const struct Maat_rule_t* rule, const char* srv_de
|
||||
key_desc=cJSON_GetObjectItem(json,"cache_key");
|
||||
if(key_desc && key_desc->type==cJSON_Object)
|
||||
{
|
||||
param->key_descr.is_not_empty=1;
|
||||
qs=cJSON_GetObjectItem(key_desc,"ignore_qs");
|
||||
if(qs && qs->type==cJSON_Array)
|
||||
{
|
||||
@@ -508,8 +514,15 @@ void cache_param_new(int idx, const struct Maat_rule_t* rule, const char* srv_de
|
||||
}
|
||||
}
|
||||
item=cJSON_GetObjectItem(key_desc,"cookie");
|
||||
if(item && item->type==cJSON_String) param->key_descr.include_cookie=tfe_strdup(item->valuestring);
|
||||
|
||||
if(item && item->type==cJSON_String)
|
||||
{
|
||||
param->key_descr.include_cookie=tfe_strdup(item->valuestring);
|
||||
|
||||
}
|
||||
if(param->key_descr.qs_num>0||param->key_descr.include_cookie!=NULL)
|
||||
{
|
||||
param->key_descr.is_not_empty=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1005,7 +1018,7 @@ enum cache_pending_result web_cache_async_pending(struct cache_handle* handle, u
|
||||
{
|
||||
_mid->cache_key=get_cache_key(request, &(param->key_descr));
|
||||
}
|
||||
TFE_LOG_DEBUG(handle->logger, "cache policy %d matched: url=%s alternative key=%s",
|
||||
TFE_LOG_DEBUG(handle->logger, "cache policy %d matched: url=%s alt-key=%s",
|
||||
cache_policy.config_id,
|
||||
request->req_spec.url,
|
||||
_mid->cache_key!=NULL?_mid->cache_key:"null");
|
||||
@@ -1204,7 +1217,7 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle,
|
||||
case ALLOWED:
|
||||
case UNDEFINED:
|
||||
if(_mid->shall_bypass
|
||||
|| content_len > param->max_cache_obj_size
|
||||
|| (param->max_cache_obj_size!=0 && content_len > param->max_cache_obj_size)
|
||||
|| (!param->cache_cookied_cont && _mid->has_cookie)
|
||||
|| (!param->cache_html && _mid->is_html))
|
||||
{
|
||||
|
||||
@@ -4,15 +4,7 @@
|
||||
#include <tfe_future.h>
|
||||
#include <MESA/Maat_rule.h>
|
||||
|
||||
enum cache_query_status
|
||||
{
|
||||
WEB_CACHE_BEFORE_QUERY=0,
|
||||
WEB_CACHE_NOT_APPLICABLE,
|
||||
WEB_CACHE_NEED_VERIFY,
|
||||
WEB_CACHE_QUERY_DATA,
|
||||
WEB_CACHE_MISS,
|
||||
WEB_CACHE_HIT
|
||||
};
|
||||
|
||||
struct cache_handle;
|
||||
struct cache_handle* create_web_cache_handle(const char* profile_path, const char* section,
|
||||
struct event_base* gc_evbase, Maat_feather_t feather, void *logger);
|
||||
@@ -49,6 +41,7 @@ enum cache_pending_result
|
||||
PENDING_RESULT_FOBIDDEN,
|
||||
PENDING_RESULT_REVALIDATE,
|
||||
PENDING_RESULT_ALLOWED,
|
||||
PENDING_RESULT_HIT,
|
||||
PENDING_RESULT_MISS
|
||||
};
|
||||
struct cache_mid;
|
||||
|
||||
Reference in New Issue
Block a user