0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-25 05:18:23 +02:00

ircd:Ⓜ️ Start a netburst interface; move cache_warm_origin; invoke from resource.

This commit is contained in:
Jason Volk 2020-04-23 03:50:03 -07:00
parent 32d624e3e9
commit ba06958d69
5 changed files with 152 additions and 46 deletions

34
include/ircd/m/burst.h Normal file
View file

@ -0,0 +1,34 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_M_BURST_H
namespace ircd::m::burst
{
struct opts;
struct burst;
extern log::log log;
};
struct ircd::m::burst::burst
{
burst(const m::node &, const opts &);
};
struct ircd::m::burst::opts
{
/// Enable gossip on netburst
bool gossip {true};
/// Enable cache warming feature on netburst
bool cache_warming {true};
};

View file

@ -95,6 +95,7 @@ namespace ircd
#include "media.h"
#include "search.h"
#include "gossip.h"
#include "burst.h"
#include "resource.h"
#include "homeserver.h"

View file

@ -127,6 +127,7 @@ libircd_matrix_la_SOURCES += user_rooms.cc
libircd_matrix_la_SOURCES += user_tokens.cc
libircd_matrix_la_SOURCES += bridge.cc
libircd_matrix_la_SOURCES += breadcrumb_rooms.cc
libircd_matrix_la_SOURCES += burst.cc
libircd_matrix_la_SOURCES += display_name.cc
libircd_matrix_la_SOURCES += event_append.cc
libircd_matrix_la_SOURCES += event_horizon.cc

108
matrix/burst.cc Normal file
View file

@ -0,0 +1,108 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
namespace ircd::m::burst
{
static void cache_warming(const node &, const opts &);
static void gossip(const node &, const opts &);
extern conf::item<seconds> cache_warmup_time;
}
decltype(ircd::m::burst::log)
ircd::m::burst::log
{
"m.burst"
};
decltype(ircd::m::burst::cache_warmup_time)
ircd::m::burst::cache_warmup_time
{
{ "name", "ircd.m.cache_warmup_time" },
{ "default", 3600L },
};
ircd::m::burst::burst::burst(const node &node,
const opts &opts)
try
{
log::debug
{
log, "Bursting to node %s",
string_view{node.node_id},
};
if(opts.cache_warming)
if(ircd::uptime() < seconds(cache_warmup_time))
cache_warming(node, opts);
if(opts.gossip)
gossip(node, opts);
}
catch(const ctx::interrupted &e)
{
throw;
}
catch(const std::exception &e)
{
log::derror
{
log, "Burst to '%s' :%s",
string_view{node.node_id},
e.what()
};
}
void
ircd::m::burst::gossip(const node &node,
const opts &opts)
try
{
}
catch(const ctx::interrupted &e)
{
throw;
}
catch(const std::exception &e)
{
log::derror
{
log, "Gossip to '%s' :%s",
string_view{node.node_id},
e.what()
};
}
/// We can smoothly warmup some memory caches after daemon startup as the
/// requests trickle in from remote servers. This function is invoked after
/// a remote contacts and reveals its identity with the X-Matrix verification.
void
ircd::m::burst::cache_warming(const node &node,
const opts &opts)
try
{
// Make a query through SRV and A records.
//net::dns::resolve(origin, net::dns::prefetch_ipport);
}
catch(const ctx::interrupted &e)
{
throw;
}
catch(const std::exception &e)
{
log::derror
{
log, "Cache warming for '%s' :%s",
string_view{node.node_id},
e.what()
};
}

View file

@ -10,24 +10,15 @@
namespace ircd::m
{
extern conf::item<seconds> cache_warmup_time;
extern conf::item<bool> x_matrix_verify_origin;
extern conf::item<bool> x_matrix_verify_destination;
static void cache_warm_origin(const resource::request &);
static pair<string_view> parse_version(const resource::request &);
static string_view authenticate_bridge(const resource::method &, const client &, resource::request &);
static user::id authenticate_user(const resource::method &, const client &, resource::request &);
static string_view authenticate_node(const resource::method &, const client &, resource::request &);
}
decltype(ircd::m::cache_warmup_time)
ircd::m::cache_warmup_time
{
{ "name", "ircd.m.cache_warmup_time" },
{ "default", 3600L },
};
decltype(ircd::m::x_matrix_verify_origin)
ircd::m::x_matrix_verify_origin
{
@ -79,14 +70,15 @@ try
*this, client, request_
};
if(request.node_id)
// If we have an error cached from previously not being able to
// contact this origin we can clear that now that they're alive.
if(request.node_id && server::errclear(fed::matrix_service(request.node_id)))
{
// If we have an error cached from previously not being able to
// contact this origin we can clear that now that they're alive.
server::errclear(fed::matrix_service(request.node_id));
// The origin was verified so we can invoke the cache warming now.
cache_warm_origin(request);
m::burst::opts opts;
m::burst::burst
{
request.node_id, opts
};
}
return function(client, request);
@ -419,33 +411,3 @@ ircd::m::parse_version(const m::resource::request &request)
name, version
};
}
/// We can smoothly warmup some memory caches after daemon startup as the
/// requests trickle in from remote servers. This function is invoked after
/// a remote contacts and reveals its identity with the X-Matrix verification.
///
/// This process helps us avoid cold caches for the first requests coming from
/// our server. Such requests are often parallel requests, for ex. to hundreds
/// of servers in a Matrix room at the same time.
///
/// This function does nothing after the cache warmup period has ended.
void
ircd::m::cache_warm_origin(const resource::request &request)
try
{
assert(request.node_id);
if(ircd::uptime() > seconds(cache_warmup_time))
return;
// Make a query through SRV and A records.
//net::dns::resolve(origin, net::dns::prefetch_ipport);
}
catch(const std::exception &e)
{
log::derror
{
resource::log, "Cache warming for '%s' :%s",
request.node_id,
e.what()
};
}