Просмотр исходного кода

Allow tuning for maximum compile time for hyperscan

tags/1.1.0
Vsevolod Stakhov 8 лет назад
Родитель
Сommit
02d74cf419
3 измененных файлов: 16 добавлений и 7 удалений
  1. 9
    1
      src/hs_helper.c
  2. 6
    5
      src/libserver/re_cache.c
  3. 1
    1
      src/libserver/re_cache.h

+ 9
- 1
src/hs_helper.c Просмотреть файл

@@ -50,11 +50,14 @@ worker_t hs_helper_worker = {
SOCK_STREAM /* TCP socket */
};

const static gdouble default_max_time = 1.0;

/*
* Worker's context
*/
struct hs_helper_ctx {
gchar *hs_dir;
gdouble max_time;
struct rspamd_config *cfg;
struct event_base *ev_base;
};
@@ -70,10 +73,15 @@ init_hs_helper (struct rspamd_config *cfg)

ctx->cfg = cfg;
ctx->hs_dir = RSPAMD_DBDIR "/";
ctx->max_time = default_max_time;

rspamd_rcl_register_worker_option (cfg, type, "cache_dir",
rspamd_rcl_parse_struct_string, ctx,
G_STRUCT_OFFSET (struct hs_helper_ctx, hs_dir), 0);
rspamd_rcl_register_worker_option (cfg, type, "max_time",
rspamd_rcl_parse_struct_time, ctx,
G_STRUCT_OFFSET (struct hs_helper_ctx, max_time),
RSPAMD_CL_FLAG_TIME_FLOAT);

return ctx;
}
@@ -138,7 +146,7 @@ rspamd_rs_compile (struct hs_helper_ctx *ctx, struct rspamd_worker *worker)
}

if ((ncompiled = rspamd_re_cache_compile_hyperscan (ctx->cfg->re_cache,
ctx->hs_dir,
ctx->hs_dir, ctx->max_time,
&err)) == -1) {
msg_err ("failed to compile re cache: %e", err);
g_error_free (err);

+ 6
- 5
src/libserver/re_cache.c Просмотреть файл

@@ -882,17 +882,18 @@ rspamd_re_cache_type_from_string (const char *str)
#ifdef WITH_HYPERSCAN
static gboolean
rspamd_re_cache_is_finite (struct rspamd_re_cache *cache,
rspamd_regexp_t *re, gint flags)
rspamd_regexp_t *re, gint flags, gdouble max_time)
{
pid_t cld;
gint status;
struct timespec ts;
hs_compile_error_t *hs_errors;
hs_database_t *test_db;
const double wait_time = 0.1;
gdouble wait_time;
const gint max_tries = 10;
gint tries = 0, rc;

wait_time = max_time / max_tries;
/* We need to restore SIGCHLD processing */
signal (SIGCHLD, SIG_DFL);
cld = fork ();
@@ -951,7 +952,7 @@ rspamd_re_cache_is_finite (struct rspamd_re_cache *cache,

gint
rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
const char *cache_dir,
const char *cache_dir, gdouble max_time,
GError **err)
{
g_assert (cache != NULL);
@@ -1039,14 +1040,14 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
&cache->plt,
&test_db,
&hs_errors) != HS_SUCCESS) {
msg_info_re_cache ("cannot compile %s to hyperscan, try prefilter match",
msg_debug_re_cache ("cannot compile %s to hyperscan, try prefilter match",
rspamd_regexp_get_pattern (re));
hs_free_compile_error (hs_errors);

/* The approximation operation might take a significant
* amount of time, so we need to check if it's finite
*/
if (rspamd_re_cache_is_finite (cache, re, hs_flags[i])) {
if (rspamd_re_cache_is_finite (cache, re, hs_flags[i], max_time)) {
hs_flags[i] |= HS_FLAG_PREFILTER;
hs_ids[i] = rspamd_regexp_get_cache_id (re);
hs_pats[i] = rspamd_regexp_get_pattern (re);

+ 1
- 1
src/libserver/re_cache.h Просмотреть файл

@@ -129,7 +129,7 @@ enum rspamd_re_type rspamd_re_cache_type_from_string (const char *str);
* Compile expressions to the hyperscan tree and store in the `cache_dir`
*/
gint rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
const char *cache_dir,
const char *cache_dir, gdouble max_time,
GError **err);



Загрузка…
Отмена
Сохранить