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

Commit

Permalink
update readme / iovec optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Feb 7, 2019
1 parent c7cd83b commit 3294cf4
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 150 deletions.
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)
32 changes: 20 additions & 12 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,32 +2015,38 @@ 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;

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;

res += vec[n].iov_len;
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
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
Loading

0 comments on commit 3294cf4

Please sign in to comment.