17 #include <gflags/gflags.h> 25 using namespace folly;
27 DEFINE_int32(clients, 1,
"Number of simulated SSL clients");
31 DEFINE_bool(sticky,
false,
"A given client sends all reqs to one " 33 DEFINE_bool(global,
false,
"All clients in a thread use the same SSL session");
34 DEFINE_bool(handshakes,
false,
"Force 100% handshakes");
63 std::shared_ptr<SSLContext>
ctx_;
69 if (session_ && !FLAGS_global)
70 SSL_SESSION_free(session_);
71 if (socket_ !=
nullptr) {
72 if (sslSocket_ !=
nullptr) {
83 void connectSuccess()
noexcept override;
97 "usage: sslcachetest [options] -c <clients> -t <threads> servers\n" 99 gflags::ParseCommandLineFlags(&argc, &argv,
true);
103 struct timeval start;
105 struct timeval result;
107 srand((
unsigned int)
time(
nullptr));
109 for (
int i = 1;
i < argc;
i++) {
113 cout <<
"require at least one server\n";
117 gettimeofday(&start,
nullptr);
118 if (FLAGS_threads == 1) {
121 gettimeofday(&end,
nullptr);
127 std::vector<ClientRunner> clients;
128 std::vector<std::thread>
threads;
129 for (
int t = 0;
t < FLAGS_threads;
t++) {
130 threads.emplace_back([&] {
134 for (
auto& thr: threads) {
137 gettimeofday(&end,
nullptr);
139 for (
const auto& client: clients) {
146 timersub(&end, &start, &result);
148 cout <<
"Requests: " << reqs << endl;
149 cout <<
"Handshakes: " << miss << endl;
150 cout <<
"Resumes: " << hits << endl;
151 cout <<
"Runtime(ms): " << result.tv_sec <<
"." << result.tv_usec / 1000 <<
154 cout <<
"ops/sec: " << (reqs * 1.0) /
155 ((double)result.tv_sec * 1.0 + (
double)result.tv_usec / 1000000.0) << endl;
164 std::list<SSLCacheClient *> clients;
165 SSL_SESSION* session =
nullptr;
167 for (
int i = 0;
i < FLAGS_clients;
i++) {
170 clients.push_back(c);
175 for (
auto it = clients.begin(); it != clients.end(); it++) {
195 ctx_->setOptions(SSL_OP_NO_TICKET);
206 if (
currReq_ == 0 || !FLAGS_sticky) {
227 if (!FLAGS_handshakes) {
230 else if (FLAGS_global &&
pSess_ !=
nullptr)
240 cout <<
"connectError: " << ex.what() << endl;
254 if (FLAGS_global &&
pSess_ !=
nullptr && *
pSess_ ==
nullptr) {
273 cout <<
"handshakeError: " << ex.what() << endl;
void handshakeSuc(AsyncSSLSocket *sock) noexceptoverride
DEFINE_int32(clients, 1,"Number of simulated SSL clients")
const struct message requests[]
std::shared_ptr< SSLContext > ctx_
virtual void sslConn(HandshakeCB *callback, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), const folly::SSLContext::SSLVerifyPeerEnum &verifyPeer=folly::SSLContext::SSLVerifyPeerEnum::USE_CTX)
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
void handshakeErr(AsyncSSLSocket *sock, const AsyncSocketException &ex) noexceptoverride
std::vector< std::thread::id > threads
virtual void connect(ConnectCallback *callback, const folly::SocketAddress &address, int timeout=0, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexcept
static void run(EventBaseManager *ebm, EventBase *eb, folly::Baton<> *stop, const StringPiece &name)
AsyncSSLSocket::UniquePtr sslSocket_
AsyncServerSocket::UniquePtr socket_
virtual bool getSSLSessionReused() const
DEFINE_bool(sticky, false,"A given client sends all reqs to one ""(random) server")
int main(int argc, char *argv[])
SSLCacheClient(EventBase *eventBase, SSL_SESSION **pSess, ClientRunner *cr)
SSL_SESSION * getSSLSession()
void connectSuccess() noexceptoverride
~SSLCacheClient() override
void setSSLSession(SSL_SESSION *session, bool takeOwnership=false)
void connectErr(const AsyncSocketException &ex) noexceptoverride
AsyncSSLSocket * sslSocket_
std::chrono::nanoseconds time()