Browse Source

Add support for the Luna C++ framework (#2692)

* Add support for the Luna C++ framework

* Fix the luna setup.sh file to point to the correctl binary. Unsure how this slipped past Travis testing the first time!

* More missing items that slipped through local testing. This is deeply embarrassing.
Don Goodman-Wilson 8 years ago
parent
commit
4555c2949f

+ 1 - 0
.travis.yml

@@ -29,6 +29,7 @@ env:
     - "TESTDIR=C++/ulib"
     - "TESTDIR=C++/wt"
     - "TESTDIR=C++/poco"
+    - "TESTDIR=C++/luna"
     - "TESTDIR=Clojure/compojure"
     - "TESTDIR=Clojure/http-kit"
     - "TESTDIR=Clojure/luminus"

+ 0 - 0
frameworks/C++/luna/.gitignore


+ 21 - 0
frameworks/C++/luna/CMakeLists.txt

@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 2.8)
+project(lunabench)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
+
+find_package( Threads )
+
+include(conanbuildinfo.cmake)
+conan_basic_setup()
+
+set(DEFAULT_SOURCE_FILES default.cpp common.h)
+add_executable(lunabench_default ${DEFAULT_SOURCE_FILES})
+target_link_libraries(lunabench_default ${CONAN_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+
+set(EPOLL_SOURCE_FILES epoll.cpp common.h)
+add_executable(lunabench_epoll ${EPOLL_SOURCE_FILES})
+target_link_libraries(lunabench_epoll ${CONAN_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+
+set(THREAD_SOURCE_FILES thread.cpp common.h)
+add_executable(lunabench_thread ${THREAD_SOURCE_FILES})
+target_link_libraries(lunabench_thread ${CONAN_LIBS} ${CMAKE_THREAD_LIBS_INIT})

+ 40 - 0
frameworks/C++/luna/README.md

@@ -0,0 +1,40 @@
+#Luna Benchmarking Test
+
+[Luna](https://github.com/DEGoodmanWilson/luna) is a web framework for modern C++, designed for low latency and high throughput. These tests use version 2.10.1 of Luna.
+
+### Source Code
+
+* [Default threading mode, with thread pool](default.cpp)
+* [epoll threading mode (linux only)](epoll.cpp)
+* [Thread-per-connection mode](thread.cpp)
+
+### Test URLs
+
+[/plaintext](http://www.techempower.com/benchmarks/#section=plaintext)
+----------
+```
+HTTP/1.1 200 OK
+Connection: Keep-Alive
+Content-Length: 13
+Server: luna/2.10.1
+Content-Type: text/plain
+Server: luna
+Date: Thu, 13 Apr 2017 11:40:58 GMT
+
+Hello, world!
+```
+
+
+[/json](http://www.techempower.com/benchmarks/#section=json)
+----------
+```
+HTTP/1.1 200 OK
+Connection: Keep-Alive
+Content-Length: 27
+Server: luna/2.10.1
+Content-Type: application/json
+Server: luna
+Date: Thu, 13 Apr 2017 11:40:58 GMT
+
+{"message":"Hello, World!"}
+```

+ 62 - 0
frameworks/C++/luna/benchmark_config.json

@@ -0,0 +1,62 @@
+{
+  "framework": "luna",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "luna",
+      "language": "C++",
+      "orm": "Raw",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Luna",
+      "notes": "",
+      "versus": ""
+    },
+    "epoll": {
+      "setup_file": "setup_epoll",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "luna",
+      "language": "C++",
+      "orm": "Raw",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Luna",
+      "notes": "",
+      "versus": ""
+    },
+    "thread-per-connection": {
+      "setup_file": "setup_thread",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "luna",
+      "language": "C++",
+      "orm": "Raw",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Luna",
+      "notes": "",
+      "versus": ""
+    }
+  }]
+}

+ 36 - 0
frameworks/C++/luna/common.h

@@ -0,0 +1,36 @@
+//
+// Created by Don Goodman-Wilson on 15/04/2017.
+//
+
+#pragma once
+
+#include <luna/luna.h>
+#include <nlohmann/json.hpp>
+
+using json = nlohmann::json;
+
+// Request handlers
+
+// /json
+auto json_handler = [](auto req) -> luna::response {
+    json j;
+    j["message"] = "Hello, World!";
+
+    return {
+            200,
+            luna::response_headers{{"Server", "luna"}},
+            "application/json",
+            j.dump(),
+    };
+};
+
+// /plaintext
+auto plaintext_handler = [](auto req) -> luna::response {
+    return {
+            200,
+            luna::response_headers{{"Server", "luna"}},
+            "text/plain",
+            "Hello, world!",
+    };
+};
+

+ 6 - 0
frameworks/C++/luna/conanfile.txt

@@ -0,0 +1,6 @@
+[requires]
+luna/2.10.1@DEGoodmanWilson/stable
+json/2.1.0@jjones646/stable
+
+[generators]
+cmake

+ 30 - 0
frameworks/C++/luna/default.cpp

@@ -0,0 +1,30 @@
+#include <iostream>
+#include <luna/luna.h>
+#include "common.h"
+
+// Main entrypoint
+
+int main(int argc, char **argv) {
+    if (argc != 3) {
+        std::cerr << "Usage: " << argv[0] << " port nthreads" << std::endl;
+        return 1;
+    }
+
+    auto port = static_cast<uint16_t>(std::atoi(argv[1]));
+    auto threads = static_cast<uint16_t>(std::atoi(argv[2]));
+
+    luna::server server{
+            luna::server::port{port},
+            luna::server::thread_pool_size{threads},
+    };
+
+    server.handle_request(luna::request_method::GET,
+                          "/plaintext",
+                          plaintext_handler);
+
+    server.handle_request(luna::request_method::GET,
+                          "/json",
+                          json_handler);
+
+    server.await();
+}

+ 31 - 0
frameworks/C++/luna/epoll.cpp

@@ -0,0 +1,31 @@
+#include <iostream>
+#include <luna/luna.h>
+#include "common.h"
+
+// Main entrypoint
+
+int main(int argc, char **argv) {
+    if (argc != 3) {
+        std::cerr << "Usage: " << argv[0] << " port nthreads" << std::endl;
+        return 1;
+    }
+
+    auto port = static_cast<uint16_t>(std::atoi(argv[1]));
+    auto threads = static_cast<uint16_t>(std::atoi(argv[2]));
+
+    luna::server server{
+            luna::server::port{port},
+            luna::server::use_epoll_if_available{true},
+            luna::server::thread_pool_size{threads},
+    };
+
+    server.handle_request(luna::request_method::GET,
+                          "/plaintext",
+                          plaintext_handler);
+
+    server.handle_request(luna::request_method::GET,
+                          "/json",
+                          json_handler);
+
+    server.await();
+}

+ 11 - 0
frameworks/C++/luna/setup.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+fw_depends luna
+
+CC=gcc-4.9 CXX=g++-4.9 conan install --build=missing -s compiler="gcc" -s compiler.version="4.9" .
+cmake . -DCMAKE_CXX_COMPILER=g++-4.9 -DCMAKE_CC_COMPILER=gcc-4.9
+cmake --build .
+
+MAX_THREADS=$((2 * $CPU_COUNT))
+
+$TROOT/bin/lunabench_default 8080 $MAX_THREADS

+ 11 - 0
frameworks/C++/luna/setup_epoll.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+fw_depends luna
+
+CC=gcc-4.9 CXX=g++-4.9 conan install --build=missing -s compiler="gcc" -s compiler.version="4.9" .
+cmake . -DCMAKE_CXX_COMPILER=g++-4.9 -DCMAKE_CC_COMPILER=gcc-4.9
+cmake --build .
+
+MAX_THREADS=$((2 * $CPU_COUNT))
+
+$TROOT/bin/lunabench_epoll 8080 $MAX_THREADS

+ 9 - 0
frameworks/C++/luna/setup_thread.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+fw_depends luna
+
+CC=gcc-4.9 CXX=g++-4.9 conan install --build=missing -s compiler="gcc" -s compiler.version="4.9" .
+cmake . -DCMAKE_CXX_COMPILER=g++-4.9 -DCMAKE_CC_COMPILER=gcc-4.9
+cmake --build .
+
+$TROOT/bin/lunabench_thread 8080

+ 29 - 0
frameworks/C++/luna/thread.cpp

@@ -0,0 +1,29 @@
+#include <iostream>
+#include <luna/luna.h>
+#include "common.h"
+
+// Main entrypoint
+
+int main(int argc, char **argv) {
+    if (argc != 2) {
+        std::cerr << "Usage: " << argv[0] << " port" << std::endl;
+        return 1;
+    }
+
+    auto port = static_cast<uint16_t>(std::atoi(argv[1]));
+
+    luna::server server{
+            luna::server::port{port},
+            luna::server::use_thread_per_connection{true},
+    };
+
+    server.handle_request(luna::request_method::GET,
+                          "/plaintext",
+                          plaintext_handler);
+
+    server.handle_request(luna::request_method::GET,
+                          "/json",
+                          json_handler);
+
+    server.await();
+}

+ 9 - 0
toolset/setup/linux/frameworks/luna.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+fw_depends gcc-4.9 conan
+
+fw_installed luna && return 0
+
+echo "" > $IROOT/luna.installed
+
+source $IROOT/luna.installed

+ 1 - 0
toolset/setup/linux/prerequisites.sh

@@ -27,6 +27,7 @@ sudo apt-get -qqy install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options:
   libjson0-dev libmcrypt-dev libicu-dev gettext \
   libpq-dev mlton \
   cloc dstat                        `# Collect resource usage statistics` \
+  python-dev \
   python-pip
 
 sudo pip install colorama==0.3.1

+ 11 - 0
toolset/setup/linux/systools/conan.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+fw_depends python-dev
+
+fw_installed conan && return 0
+
+pip install --user conan
+
+echo -e "export PATH=~/.local/bin:\$PATH" > $IROOT/conan.installed
+
+source $IROOT/conan.installed