Commit 3f3874d1 authored by Alex Hultman's avatar Alex Hultman
Browse files

Add testReceivePerformance test, boost parser performance 4x

parent 9ff91e50
......@@ -105,8 +105,8 @@ private:
if (int(payLength) <= int(length - MESSAGE_HEADER)) {
if (isServer) {
unmaskImpreciseCopyMask(src, src + MESSAGE_HEADER, src + MESSAGE_HEADER - 4, payLength);
if (handleFragment(src, payLength, 0, opCode[(unsigned char) opStack], isFin(frame), user)) {
unmaskImpreciseCopyMask(src + MESSAGE_HEADER - 4, src + MESSAGE_HEADER, src + MESSAGE_HEADER - 4, payLength);
if (handleFragment(src + MESSAGE_HEADER - 4, payLength, 0, opCode[(unsigned char) opStack], isFin(frame), user)) {
return true;
}
} else {
......
......@@ -1000,26 +1000,83 @@ void serveHttp() {
h.run();
}
void testReceivePerformance() {
// "Rock it with HTML5 WebSockets!"
unsigned char webSocketMessage[] = {0x81, 0x9c, 0x37, 0x22, 0x79, 0xa5, 0x65, 0x4d, 0x1a, 0xce, 0x17, 0x4b, 0x0d, 0x85, 0x40, 0x4b
,0x0d, 0xcd, 0x17, 0x6a, 0x2d, 0xe8, 0x7b, 0x17, 0x59, 0xf2, 0x52, 0x40, 0x2a, 0xca, 0x54, 0x49
,0x1c, 0xd1};
// time this!
int messages = 1000000;
size_t bufferLength = sizeof(webSocketMessage) * messages;
char *buffer = new char[bufferLength + 4];
char *originalBuffer = new char[bufferLength];
for (int i = 0; i < messages; i++) {
memcpy(originalBuffer + sizeof(webSocketMessage) * i, webSocketMessage, sizeof(webSocketMessage));
}
uWS::Hub h;
h.onError([](void *user) {
std::cout << "FAILURE: " << user << " should not emit error!" << std::endl;
exit(-1);
});
struct TestWebSocket : uWS::WebSocket<uWS::SERVER> {
void onData(char *data, size_t length) {
consume(data, length, this);
}
};
h.onConnection([originalBuffer, buffer, bufferLength, messages, &h](uWS::WebSocket<uWS::SERVER> *ws, uWS::HttpRequest req) {
for (int i = 0; i < 100; i++) {
memcpy(buffer, originalBuffer, bufferLength);
auto now = std::chrono::high_resolution_clock::now();
((TestWebSocket *) ws)->onData(buffer, bufferLength);
int us = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - now).count();
std::cout << "Messages per microsecond: " << (double(messages) / double(us)) << std::endl;
}
h.getDefaultGroup<uWS::SERVER>().close();
});
h.onMessage([](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) {
});
h.listen(3000);
h.connect("ws://localhost:3000", nullptr);
h.run();
delete [] buffer;
delete [] originalBuffer;
}
int main(int argc, char *argv[])
{
//serveEventSource();
//serveHttp();
//serveBenchmark();
// performance tests (run without asan!)
testReceivePerformance();
// falls through
testHTTP();
testSmallSends();
testSendCallback();
testMultithreading();
testReusePort();
testStress();
testRouting();
testClosing();
testConnections();
testListening();
testBroadcast();
testMessageBatch();
testAutoPing();
// testHTTP();
// testSmallSends();
// testSendCallback();
// testMultithreading();
// testReusePort();
// testStress();
// testRouting();
// testClosing();
// testConnections();
// testListening();
// testBroadcast();
// testMessageBatch();
// testAutoPing();
//testAutobahn();
}
......@@ -30,9 +30,9 @@ HEADERS += ../src/WebSocketProtocol.h \
../src/Epoll.h \
../src/Asio.h
LIBS += -lasan -lssl -lcrypto -lz -lpthread -luv -lboost_system
LIBS += -lssl -lcrypto -lz -lpthread -luv -lboost_system
QMAKE_CXXFLAGS += -fsanitize=address -Wno-unused-parameter
QMAKE_CXXFLAGS += -Wno-unused-parameter
QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE *= -O3 -g
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment