Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:criticalstack/libevhtp into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Aug 2, 2019
2 parents c72faaf + 00ccb5c commit f78d0a8
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 210 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

project(libevhtp VERSION "1.2.17")
project(libevhtp VERSION "1.2.18")

# For us YCM users.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down
12 changes: 11 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
v1.2.17
v1.2.18
o Add htp__evbuffer_add_iovec_ helper for libevent < 2.1 (8991567 Nathan French)
o [#122] Fix compilation without deprecated OpenSSL 1.1 APIs (78e8e41 Rosen Penev)
o [#122] Reorganize OpenSSL < 1.0.0 compatibility for greater readability. (8e543fe Rosen Penev)
o [#123] add missing include <sys/types.h> for ssize_t (6a74ec7 maxice8)
o [#123] include sys/types only if EVHTP_HAS_SYS_TYPES is set (0839f8e Nathan French)
o [#122] cleanup for ssl locking changes (7d0fd5d Nathan French)
o better get0_notBefore ssl defs (8ae5cdd Nathan French)
o cleanup / optimization for iovec operations (874a225 Nathan French)

v1.2.17 (alpha/beta)
o [#111] assert frontends not compiled with -DNDEBUG (07d6f5f Nathan French)
o [#111] Remove asserts for alloc functions. (#112) (114bf53 Nathan French)
o [#108] do not include content-length with chunked (#113) (73255df Nathan French)
Expand Down
135 changes: 0 additions & 135 deletions README.markdown

This file was deleted.

49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
| ![LOGO](http://i.imgur.com/uBd4iIz.png) | <h1>Libevhtp</h1> |
| :------------- | -------------: |

[![Build Status](https://travis-ci.org/criticalstack/libevhtp.svg?branch=develop)](https://travis-ci.org/criticalstack/libevhtp)
[![Gitter](https://badges.gitter.im/criticalstack/libevhtp.svg)](https://gitter.im/criticalstack/libevhtp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Packaging status](https://repology.org/badge/tiny-repos/libevhtp.svg)](https://repology.org/metapackage/libevhtp/versions)

<a href="https://scan.coverity.com/projects/libevhtp">
<img alt="Coverity Scan Build Status"
src="https://scan.coverity.com/projects/15294/badge.svg"/>
</a>

## Required Dependencies
* [gcc](http://gcc.gnu.org/) or [clang](https://clang.llvm.org/)
* [Libevent2](http://libevent.org)
* [CMake](http://cmake.org)

## Optional Dependencies
* [OpenSSL](http://openssl.org)
* pthreads
* [onig (regex)](https://github.com/kkos/oniguruma)

## Building
* cd build
* cmake ..
* make
* make examples

## For Windows MinGW
* cmake -G "MSYS Makefiles" -DCMAKE_INCLUDE_PATH=/mingw/include -DCMAKE_LIBRARY_PATH=/mingw/lib -DCMAKE_INSTALL_PREFIX=/mingw .
* make

## Performance stuff

While we never documented any benchmark publically,
the popular open source project [ZIMG](http://zimg.buaa.us) did a bit of that
for us.The ZIMG team decided to move away from NGINX to libevhtp for their
software, and the results were pretty outstanding. Here is a graph showing their
application under very high load

![ZIMG GRAPH](/zimg_vs_nginx.png)

The X-axis is the number of connections, while the Y-axis is requests per
second.

You can read the whole article here: [Architecture Design of an Image Server](http://zimg.buaa.us/documents/Architecture_Design_of_Image_Server/)

Slightly outdated (Now faster!)
![HI NGINX](http://i.imgur.com/kiSkSLH.png)
102 changes: 38 additions & 64 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @brief implementation file for libevhtp.
*/

#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
Expand All @@ -12,6 +13,7 @@
#include <strings.h>
#include <inttypes.h>
#include <stdbool.h>
#include <sys/param.h> /* MIN/MAX macro */
#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -2013,51 +2015,50 @@ htp__request_parse_fini_(htparser * p)
return 0;
} /* htp__request_parse_fini_ */

static size_t
static int
htp__evbuffer_add_iovec_(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec)
{
#if LIBEVENT_VERSION_NUMBER < 0x02010000
int n;
size_t res;
size_t to_alloc;
char * bufptr;
size_t to_copy;

res = to_alloc = 0;
to_alloc = 0;

for (n = 0; n < n_vec; n++) {
to_alloc += vec[n].iov_len;
}

evbuffer_expand(buf, to_alloc);
char buffer[to_alloc];

for (n = 0; n < n_vec; n++) {
evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len);
bufptr = buffer;
to_copy = to_alloc;

res += vec[n].iov_len;
for (n = 0; n < n_vec; n++)
{
size_t copy = MIN(vec[n].iov_len, to_copy);

bufptr = mempcpy(bufptr, vec[n].iov_base, copy);
to_copy -= copy;

if (evhtp_unlikely(to_copy == 0)) {
break;
}
}

return res;
#else
return evbuffer_add_iovec(buf, vec, n_vec);
#endif
return evbuffer_add(buf, buffer, to_alloc);
}

static int
htp__create_headers_(evhtp_header_t * header, void * arg)
{
struct evbuffer * buf = arg;
struct evbuffer_iovec iov[4];

iov[0].iov_base = header->key;
iov[0].iov_len = header->klen;

iov[1].iov_base = ": ";
iov[1].iov_len = 2;

iov[2].iov_base = header->val;
iov[2].iov_len = header->vlen;

iov[3].iov_base = "\r\n";
iov[3].iov_len = 2;
struct evbuffer * buf = arg;
struct evbuffer_iovec iov[4] = {
{ header->key, header->klen },
{ ": ", 2 },
{ header->val, header->vlen },
{ "\r\n", 2 }
};

htp__evbuffer_add_iovec_(buf, iov, 4);

Expand Down Expand Up @@ -2168,45 +2169,18 @@ htp__create_reply_(evhtp_request_t * request, evhtp_res code)
* of the header.
*/
{
struct evbuffer_iovec iov[9];
const char * status_str = status_code_to_str(code);

/* data == "HTTP/" */
iov[0].iov_base = "HTTP/";
iov[0].iov_len = 5;

/* data == "HTTP/X" */
iov[1].iov_base = (void *)&major;
iov[1].iov_len = 1;

/* data == "HTTP/X." */
iov[2].iov_base = ".";
iov[2].iov_len = 1;

/* data == "HTTP/X.X" */
iov[3].iov_base = (void *)&minor;
iov[3].iov_len = 1;


/* data == "HTTP/X.X " */
iov[4].iov_base = " ";
iov[4].iov_len = 1;

/* data == "HTTP/X.X YYY" */
iov[5].iov_base = out_buf;
iov[5].iov_len = strlen(out_buf);

/* data == "HTTP/X.X YYY " */
iov[6].iov_base = " ";
iov[6].iov_len = 1;

/* data == "HTTP/X.X YYY ZZZ" */
iov[7].iov_base = (void *)status_str;
iov[7].iov_len = strlen(status_str);

/* data == "HTTP/X.X YYY ZZZ\r\n" */
iov[8].iov_base = "\r\n";
iov[8].iov_len = 2;
struct evbuffer_iovec iov[9] = {
{ "HTTP/1", 5 }, /* data == "HTTP/" */
{ (void *)&major, 1 }, /* data == "HTTP/X */
{ ".", 1 }, /* data == "HTTP/X." */
{ (void *)&minor, 1 }, /* data == "HTTP/X.X" */
{ " ", 1 }, /* data == "HTTP/X.X " */
{ out_buf, strlen(out_buf) }, /* data = "HTTP/X.X YYY" */
{ " ", 1 }, /* data = "HTTP/X.X YYY " */
{ (void *)status_str, strlen(status_str) }, /* data = "HTTP/X.X YYY ZZZ" */
{ "\r\n", 2 }, /* data = "HTTP/X.X YYY ZZZ\r\n" */
};

htp__evbuffer_add_iovec_(buf, iov, 9);
}
Expand Down
11 changes: 9 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ add_executable(example_request_fini EXCLUDE_FROM_ALL example_request_fini.c)
add_executable(example_basic EXCLUDE_FROM_ALL example_basic.c)

if(NOT EVHTP_DISABLE_EVTHR)
#add_executable(example_locality EXCLUDE_FROM_ALL example_locality.c)
#target_link_libraries(example_locality evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
if ("${CMAKE_SYSTEM}" MATCHES "Linux")
add_executable(example_locality EXCLUDE_FROM_ALL example_locality.c)
target_link_libraries(example_locality evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})

add_executable(reuse_thread_svr EXCLUDE_FROM_ALL reuse_thread_svr.c)
target_link_libraries(reuse_thread_svr evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})

add_dependencies(examples example_locality reuse_thread_svr)
endif()

add_executable(test_proxy EXCLUDE_FROM_ALL test_proxy.c)
target_link_libraries(test_proxy evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
Expand Down
5 changes: 4 additions & 1 deletion examples/example_locality.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

#include <pthread.h>
#include <sched.h>
#include <linux/bpf.h>
#include <linux/filter.h>

#include <evhtp/thread.h>
#include <evhtp/evhtp.h>

#ifndef SO_ATTACH_REUSEPORT_CBPF
#define SO_ATTACH_REUSEPORT_CBPF 51
#endif

#define CPU__COUNT sysconf(_SC_NPROCESSORS_ONLN)

static int _init = 0;
Expand Down
Loading

0 comments on commit f78d0a8

Please sign in to comment.