增加缓存上传最小文件尺寸的限制(默认16KB),增加最大suspend数的限制(默认1百万)
This commit is contained in:
@@ -63,6 +63,7 @@ enum pangu_http_stat
|
||||
STAT_ACTION_PRE_REPLACE,
|
||||
STAT_ACTION_REPLACE,
|
||||
STAT_ACTION_WHITELSIT,
|
||||
STAT_SUSPENDING,
|
||||
__PG_STAT_MAX
|
||||
};
|
||||
struct pangu_rt
|
||||
@@ -77,6 +78,7 @@ struct pangu_rt
|
||||
char * reject_page;
|
||||
int page_size;
|
||||
|
||||
long long suspend_max;
|
||||
int cache_enabled;
|
||||
struct cache_handle* cache;
|
||||
|
||||
@@ -197,6 +199,7 @@ static void pangu_http_stat_init(struct pangu_rt * pangu_runtime)
|
||||
spec[STAT_ACTION_PRE_REPLACE]="pre_replace";
|
||||
spec[STAT_ACTION_REPLACE]="replace";
|
||||
spec[STAT_ACTION_WHITELSIT]="whitelist";
|
||||
spec[STAT_SUSPENDING]="suspending";
|
||||
|
||||
for(i=0;i<__PG_STAT_MAX;i++)
|
||||
{
|
||||
@@ -313,7 +316,7 @@ int pangu_http_init(struct tfe_proxy * proxy)
|
||||
{
|
||||
const char * profile = "./conf/pangu/pangu_pxy.conf";
|
||||
const char * logfile = "./log/pangu_pxy.log";
|
||||
int table_id=0;
|
||||
int table_id=0, temp=0;
|
||||
|
||||
g_pangu_rt = ALLOC(struct pangu_rt, 1);
|
||||
g_pangu_rt->thread_num = tfe_proxy_get_work_thread_count();
|
||||
@@ -365,6 +368,9 @@ int pangu_http_init(struct tfe_proxy * proxy)
|
||||
MESA_load_profile_string_def(profile, "TEMPLATE", "PAGE_451", page_path, sizeof(page_path),
|
||||
"./resource/pangu/HTTP451.html");
|
||||
g_pangu_rt->tpl_451 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP);
|
||||
|
||||
MESA_load_profile_int_def(profile, "TANGO_CACHE", "suspend_max", &(temp), 1024*1024);
|
||||
g_pangu_rt->suspend_max=temp;
|
||||
|
||||
MESA_load_profile_int_def(profile, "TANGO_CACHE", "enable_cache", &(g_pangu_rt->cache_enabled), 1);
|
||||
if(g_pangu_rt->cache_enabled)
|
||||
@@ -1083,6 +1089,7 @@ static void cache_read_on_succ(future_result_t * result, void * user)
|
||||
ctx->cache_result_declared_sz=meta->content_length;
|
||||
ctx->resumed_cb=dummy_resume;
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
|
||||
ctx->cached_response=tfe_http_session_response_create(ctx->ref_session, 200);
|
||||
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_CONT_TYPE, meta->content_type);
|
||||
@@ -1116,6 +1123,7 @@ static void cache_read_on_succ(future_result_t * result, void * user)
|
||||
ctx->pending_result=PENDING_RESULT_MISS;
|
||||
ctx->resumed_cb=dummy_resume;
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
future_destroy(ctx->f_cache_query);
|
||||
ctx->f_cache_query=NULL;
|
||||
break;
|
||||
@@ -1133,6 +1141,7 @@ static void cache_read_on_fail(enum e_future_error err, const char * what, void
|
||||
{
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
ctx->resumed_cb=dummy_resume;
|
||||
ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1149,6 +1158,7 @@ static void cache_pend_on_succ(future_result_t * result, void * user)
|
||||
meta=cache_pending_result_read_meta(result);
|
||||
ctx->resumed_cb=dummy_resume;
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
future_destroy(ctx->f_cache_pending);
|
||||
ctx->f_cache_pending=NULL;
|
||||
if(meta==NULL)
|
||||
@@ -1193,7 +1203,8 @@ static void cache_pend_on_fail(enum e_future_error err, const char * what, void
|
||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||
|
||||
ctx->pending_result=PENDING_RESULT_FOBIDDEN;
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
tfe_http_session_resume(ctx->ref_session);
|
||||
ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
ctx->resumed_cb=dummy_resume;
|
||||
future_destroy(ctx->f_cache_pending);
|
||||
ctx->f_cache_pending=NULL;
|
||||
@@ -1203,6 +1214,11 @@ static void cache_pend_on_fail(enum e_future_error err, const char * what, void
|
||||
|
||||
void cache_pend(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
{
|
||||
if(g_pangu_rt->stat_val[STAT_SUSPENDING]>g_pangu_rt->suspend_max)
|
||||
{
|
||||
ctx->pending_result=PENDING_RESULT_FOBIDDEN;
|
||||
return;
|
||||
}
|
||||
ctx->f_cache_pending=future_create("cache_pend", cache_pend_on_succ, cache_pend_on_fail, ctx);
|
||||
ctx->ref_session=tfe_http_session_allow_write(session);
|
||||
ctx->pending_result=web_cache_async_pending(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_pending);
|
||||
@@ -1210,6 +1226,7 @@ void cache_pend(const struct tfe_http_session * session, unsigned int thread_id,
|
||||
{
|
||||
case PENDING_RESULT_REVALIDATE:
|
||||
tfe_http_session_suspend(ctx->ref_session);
|
||||
ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
break;
|
||||
case PENDING_RESULT_ALLOWED:
|
||||
case PENDING_RESULT_FOBIDDEN:
|
||||
@@ -1224,12 +1241,17 @@ void cache_pend(const struct tfe_http_session * session, unsigned int thread_id,
|
||||
}
|
||||
void cache_read(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
{
|
||||
if(g_pangu_rt->stat_val[STAT_SUSPENDING]>g_pangu_rt->suspend_max)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ctx->f_cache_query=future_create("cache_read", cache_read_on_succ, cache_read_on_fail, ctx);
|
||||
int ret=web_cache_async_read(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_query);
|
||||
if(ret==0)
|
||||
{
|
||||
ctx->ref_session=tfe_http_session_allow_write(session);
|
||||
tfe_http_session_suspend(ctx->ref_session);
|
||||
ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_SUSPENDING]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user