facebook / wangle

Wangle is a framework providing a set of common client/server abstractions for building services in a consistent, modular, and composable way.
Apache License 2.0
3.04k stars 535 forks source link

how to Improve performance? #129

Open alexliyu7352 opened 6 years ago

alexliyu7352 commented 6 years ago

Thanks for your job, you did a great project.However, I encountered performance problems in my project

I did some benchmark for pingpong, but the result is sad. On my pc(amd fx8350, 16g ram, ubuntu16.04) the result of wangle test with 8 thread is

` W0424 01:17:14.667428 12226 client_fixed_size.cc:124] name=./benchmark_pingpong_client_fixed_size 63656968192 total bytes read W0424 01:17:14.667443 12226 client_fixed_size.cc:125] name=./benchmark_pingpong_client_fixed_size 16556827 total messages read W0424 01:17:14.667455 12226 client_fixed_size.cc:126] name=./benchmark_pingpong_client_fixed_size 3844.76 average message size W0424 01:17:14.667485 12226 client_fixed_size.cc:127] name=./benchmark_pingpong_client_fixed_size 607.08 MiB/s throughput

` 607.08 MiB/s

but the same client to the asio server is

` W0424 01:19:32.815338 12311 client_fixed_size.cc:124] name=./benchmark_pingpong_client_fixed_size 157147705344 total bytes read W0424 01:19:32.815352 12311 client_fixed_size.cc:125] name=./benchmark_pingpong_client_fixed_size 38366139 total messages read W0424 01:19:32.815363 12311 client_fixed_size.cc:126] name=./benchmark_pingpong_client_fixed_size 4096 average message size W0424 01:19:32.815392 12311 client_fixed_size.cc:127] name=./benchmark_pingpong_client_fixed_size 1498.68 MiB/s throughput

` the asio test code is https://github.com/huyuguang/asio_benchmark

my wangle echo server code is

` /*

include <wangle/bootstrap/ServerBootstrap.h>

include <wangle/channel/AsyncSocketHandler.h>

include <wangle/codec/LineBasedFrameDecoder.h>

include <wangle/codec/StringCodec.h>

include <wangle/channel/OutputBufferingHandler.h>

using namespace folly; using namespace wangle;

DEFINE_int32(port, 8080, "echo server port");

typedef Pipeline<IOBufQueue&, std::unique_ptr> EchoPipeline;

// the main logic of our echo server; receives a string and writes it straight // back class EchoHandler : public BytesToBytesHandler { public:

void read(Context *ctx, IOBufQueue &msg) override {
    ctx->fireWrite(msg.move());
}

};

// where we define the chain of handlers for each messeage received class EchoPipelineFactory : public PipelineFactory { public: EchoPipeline::Ptr newPipeline( std::shared_ptr sock) override {

    auto pipeline = EchoPipeline::create();
    pipeline->addBack(AsyncSocketHandler(sock));

// pipeline->addBack(LineBasedFrameDecoder()); // pipeline->addBack(StringCodec()); pipeline->addBack(EchoHandler()); // pipeline->addBack(OutputBufferingHandler()); pipeline->finalize(); return pipeline; } };

class MyAsyncServerSocketFactory:public AsyncServerSocketFactory{ public: public: std::shared_ptr newSocket( folly::SocketAddress address, int /backlog/, bool reuse, const ServerSocketConfig& config) override {

    auto* evb = folly::EventBaseManager::get()->getEventBase();
    std::shared_ptr<folly::AsyncServerSocket> socket(
            new folly::AsyncServerSocket(evb),
            ThreadSafeDestructor());
    socket->setMaxNumMessagesInQueue(
            config.maxNumPendingConnectionsPerWorker);
    socket->setReusePortEnabled(reuse);
    if (config.enableTCPFastOpen) {
        socket->setTFOEnabled(true, config.fastOpenQueueSize);
    }
    socket->setZeroCopy(true);
    socket->setKeepAliveEnabled(true);
    socket->setMaxAcceptAtOnce(65535);
    socket->bind(address);

    socket->listen(config.acceptBacklog);
    socket->startAccepting();

    return socket;
}

};

int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true);

ServerBootstrap<EchoPipeline> server;
ServerSocketConfig config;

config.acceptBacklog = 65535;
config.maxNumPendingConnectionsPerWorker = 65535;
config.enableTCPFastOpen = true;
config.fastOpenQueueSize = 65535;
config.acceptBacklog = 65535;

server.channelFactory(std::make_shared<MyAsyncServerSocketFactory>());
server.acceptorConfig(config);
server.childPipeline(std::make_shared<EchoPipelineFactory>());
server.bind(FLAGS_port);
server.waitForStop();

return 0;

}

` The result is wangle need more ram and cpu than asio, but the throughput is much low. the another test with clean libevent also better than wangle, and same as asio. Please tell me how to Improve performance? What should I do?Because I need an high performance server. Please help me! Thanks

alexliyu7352 commented 6 years ago

the client code is https://github.com/huyuguang/asio_benchmark/blob/master/client2.cpp or https://github.com/Qihoo360/evpp/blob/master/benchmark/throughput/evpp/client_fixed_size.cc

alishir commented 5 years ago

did you build wangle in release mode?