chore(server): Usability improvements

1. Relax processor requirements for Dragonfly. Fixes #124.
2. Introduce cmake option DF_USE_SSL to allow building DF without SSL support. Fixes #128.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2022-06-15 19:19:59 +03:00
parent 4ec2538204
commit a1c3d8e33d
7 changed files with 37 additions and 7 deletions

View File

@ -14,6 +14,7 @@ set(CMAKE_CXX_STANDARD 17)
# they just disappear.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/helio/cmake" ${CMAKE_MODULE_PATH})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DF_USE_SSL "Provide support for SSL connections" ON)
include(third_party)
message(STATUS "after thirdpary")

2
helio

@ -1 +1 @@
Subproject commit 439b47b13ac5260ce0ba094e8166c2170965387b
Subproject commit 445ebf76b96b7360982f2b3c4558ec347ba3adb5

View File

@ -27,7 +27,7 @@ index d46e650c..e347e614 100644
+uname_m := $(shell uname -m)
+ifeq ($(uname_m),x86_64)
+OPTFLAGS= -march=broadwell
+OPTFLAGS= -march=sandybridge
+else ifeq ($(uname_m), aarch64)
+OPTFLAGS= -march=armv8.2-a+fp16+rcpc+dotprod+crypto
+else

View File

@ -381,8 +381,10 @@ void RobjWrapper::MakeInnerRoom(size_t current_cap, size_t desired, pmr::memory_
inner_obj_ = newp;
}
#pragma GCC push_options
#pragma GCC optimize("Ofast")
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC push_options
#pragma GCC optimize("Ofast")
#endif
// len must be at least 16
void ascii_pack(const char* ascii, size_t len, uint8_t* bin) {
@ -460,7 +462,9 @@ bool compare_packed(const uint8_t* packed, const char* ascii, size_t ascii_len)
return true;
}
#pragma GCC pop_options
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC pop_options
#endif
} // namespace detail

View File

@ -1,7 +1,13 @@
add_library(dfly_facade dragonfly_listener.cc dragonfly_connection.cc facade.cc
memcache_parser.cc redis_parser.cc reply_builder.cc)
if (DF_USE_SSL)
set(TLS_LIB tls_lib)
target_compile_definitions(dfly_facade PRIVATE DFLY_USE_SSL)
endif()
cxx_link(dfly_facade base uring_fiber_lib fibers_ext strings_lib http_server_lib
tls_lib TRDP::mimalloc TRDP::dconv)
${TLS_LIB} TRDP::mimalloc TRDP::dconv)
add_library(facade_test facade_test.cc)
cxx_link(facade_test dfly_facade gtest_main_ext)

View File

@ -17,7 +17,11 @@
#include "facade/redis_parser.h"
#include "facade/service_interface.h"
#include "util/fiber_sched_algo.h"
#ifdef DFLY_USE_SSL
#include "util/tls/tls_socket.h"
#endif
#include "util/uring/uring_socket.h"
ABSL_FLAG(bool, tcp_nodelay, false,
@ -181,6 +185,7 @@ void Connection::HandleRequests() {
auto remote_ep = lsb->RemoteEndpoint();
#ifdef DFLY_USE_SSL
unique_ptr<tls::TlsSocket> tls_sock;
if (ctx_) {
tls_sock.reset(new tls::TlsSocket(socket_.get()));
@ -193,8 +198,11 @@ void Connection::HandleRequests() {
}
VLOG(1) << "TLS handshake succeeded";
}
FiberSocketBase* peer = tls_sock ? (FiberSocketBase*)tls_sock.get() : socket_.get();
#else
FiberSocketBase* peer = socket_.get();
#endif
io::Result<bool> http_res{false};
if (absl::GetFlag(FLAGS_http_admin_console))
http_res = CheckForHttpProto(peer);

View File

@ -4,7 +4,9 @@
#include "facade/dragonfly_listener.h"
#ifdef DFLY_USE_SSL
#include <openssl/ssl.h>
#endif
#include "base/flags.h"
#include "base/logging.h"
@ -47,6 +49,8 @@ using namespace util;
using absl::GetFlag;
namespace {
#ifdef DFLY_USE_SSL
// To connect: openssl s_client -cipher "ADH:@SECLEVEL=0" -state -crlf -connect 127.0.0.1:6380
static SSL_CTX* CreateSslCntx() {
SSL_CTX* ctx = SSL_CTX_new(TLS_server_method());
@ -90,6 +94,7 @@ static SSL_CTX* CreateSslCntx() {
return ctx;
}
#endif
bool ConfigureKeepAlive(int fd, unsigned interval_sec) {
DCHECK_GT(interval_sec, 3u);
@ -121,17 +126,23 @@ bool ConfigureKeepAlive(int fd, unsigned interval_sec) {
} // namespace
Listener::Listener(Protocol protocol, ServiceInterface* si) : service_(si), protocol_(protocol) {
#ifdef DFLY_USE_SSL
if (GetFlag(FLAGS_tls)) {
OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
ctx_ = CreateSslCntx();
}
#endif
http_base_.reset(new HttpListener<>);
http_base_->set_resource_prefix("https://romange.s3.eu-west-1.amazonaws.com/static");
si->ConfigureHttpHandlers(http_base_.get());
}
Listener::~Listener() {
#ifdef DFLY_USE_SSL
SSL_CTX_free(ctx_);
#endif
}
util::Connection* Listener::NewConnection(ProactorBase* proactor) {