Repository navigation
Open
Description
I modify the telnet example to echo protocol.
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <gflags/gflags.h>
#include <wangle/bootstrap/ServerBootstrap.h>
#include <wangle/channel/AsyncSocketHandler.h>
#include <wangle/codec/LineBasedFrameDecoder.h>
#include <wangle/codec/FixedLengthFrameDecoder.h>
#include <wangle/codec/StringCodec.h>
using namespace folly;
using namespace wangle;
DEFINE_int32(port, 8096, "echo server port");
DEFINE_int32(frame_length, 10, "echo frame length");
typedef Pipeline<IOBufQueue&, std::string> EchoPipeline;
class EchoHandler : public HandlerAdapter<std::string> {
public:
virtual void read(Context* ctx, std::string msg) override {
if (msg.empty())
{
write(ctx, "Please type something.\r\n");
}
else if (msg == "bye")
{
write(ctx, "Have a fabulous day!\r\n").then([ctx, this]{
close(ctx);
});
}
else
{
write(ctx, msg);
}
}
virtual void transportActive(Context* ctx) override {
auto sock = ctx->getTransport();
SocketAddress localAddress;
sock->getLocalAddress(&localAddress);
//write(ctx, "Welcome to " + localAddress.describe() + "!\r\n");
std::cout << "Welcome to " + localAddress.describe() + "!\r\n" << std::endl;
//write(ctx, "Type 'bye' to disconnect.\r\n");
}
};
class EchoPipelineFactory : public PipelineFactory<EchoPipeline> {
public:
EchoPipeline::Ptr newPipeline(std::shared_ptr<AsyncTransportWrapper> sock) {
auto pipeline = EchoPipeline::create();
pipeline->addBack(AsyncSocketHandler(sock));
pipeline->addBack(FixedLengthFrameDecoder(FLAGS_frame_length));
pipeline->addBack(StringCodec());
pipeline->addBack(EchoHandler());
pipeline->finalize();
return pipeline;
}
};
int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
ServerBootstrap<EchoPipeline> server;
server.childPipeline(std::make_shared<EchoPipelineFactory>());
server.bind(FLAGS_port);
server.waitForStop();
return 0;
}
I test it use my echoclient with 10 bytes playload,then the qps is only 13w。
My hardware:
model name : Intel(R) Xeon(R) CPU E5-2450 v2 @ 2.50GHz
cpu MHz : 2500.000
cache size : 20480 KB
MemTotal: 132133772 kB
OS:
CentOS release 6.3 (Final) with gcc 4.8
Metadata
Metadata
Assignees
Labels
No labels
Activity
djwatson commentedon Dec 22, 2015
The qps is only 13? I'm not sure I quite follow.
No, we don't have an official benchmark.
Accepts will be limited by the kernel lock limit (even with SO_REUSEPORT).
For raw throughput on small frames, Proxygen gets ~20k / s, fbthrift gets upwards of 500k/s with pipelining turned up. More if you start disabling some of the stats features.
billowqiu commentedon Dec 23, 2015
Qps is not only 13,but 130k/s, its mine fault.
Accepts hasn't problem.
But i use the same client with libeven,its qps can get 400k/s
wangle/service:ServiceTest: fix ASAN test
Fix memory leak in EvbHandshakeHelperTest::TestDropConnection.