#64 key keeper增加evdnsbase参数。

避免创建大量dnsbase,耗尽fd。ssl stream/tcp stream/proxy也做了相应修改。
This commit is contained in:
zhengchao
2018-11-26 14:54:20 +08:00
parent 35c2559f8a
commit ce9d7fa5eb
13 changed files with 82 additions and 47 deletions

View File

@@ -8,6 +8,8 @@ const char * tfe_proxy_default_conffile();
const char * tfe_proxy_default_logger();
unsigned int tfe_proxy_get_work_thread_count();
struct event_base * tfe_proxy_get_work_thread_evbase(unsigned int thread_id);
struct evdns_base* tfe_proxy_get_work_thread_dnsbase(unsigned int thread_id);
struct event_base * tfe_proxy_get_gc_evbase(void);
screen_stat_handle_t tfe_proxy_get_fs_handle(void);

View File

@@ -1,6 +1,7 @@
#pragma once
#include "tfe_future.h"
#include "event2/event.h"
#include <event2/event.h>
#include <event2/dns.h>
struct tfe_rpc_response_result{
int status_code;
@@ -24,4 +25,6 @@ enum TFE_RPC_METHOD
struct tfe_rpc_response_result* tfe_rpc_release(void* result);
void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag, const char* data, int data_len, struct event_base * evbase);
void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag,
const char* data, int data_len, struct event_base * evbase, struct evdns_base* dnsbase);

View File

@@ -178,18 +178,14 @@ char* get_request_url(struct evhttp_uri* uri, int url_len)
}
//data is for POST. if method is GET, data should be NULL
void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag, const char* data, int data_len, struct event_base * evbase)
void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag, const char* data, int data_len, struct event_base * evbase, struct evdns_base* dnsbase)
{
struct promise* p = future_to_promise(f);
struct tfe_rpc_ctx* ctx = ALLOC(struct tfe_rpc_ctx, 1);
ctx->evbase = evbase;
ctx->flag = flag;
promise_set_ctx(p, (void*)ctx, tfe_rpc_promise_free_ctx);
if(!evbase)
{
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "event base is NULL");
return;
}
assert(evbase&&dnsbase);
struct evhttp_uri* uri = evhttp_uri_parse(url);
if(NULL == uri)
{
@@ -207,13 +203,7 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
{
port = 80;
}
//printf("url:%s host:%s port:%d path:%s query:%s request_url:%s\n", url, host, port, path, query, request_url);
struct evdns_base* dnsbase = evdns_base_new(evbase, EVDNS_BASE_INITIALIZE_NAMESERVERS);
if (!dnsbase)
{
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "create dns base failed!");
return;
}
struct evhttp_connection* connection = evhttp_connection_base_new(evbase, dnsbase, host, port);
if (!connection)
{