diff --git a/Feersum.xs b/Feersum.xs index e456d82..952cac2 100644 --- a/Feersum.xs +++ b/Feersum.xs @@ -7,13 +7,10 @@ #include #include #include +#include #include "ppport.h" -#include "picohttpparser-git/picohttpparser.c" - -#include "rinq.c" - #ifdef __GNUC__ # define likely(x) __builtin_expect(!!(x), 1) # define unlikely(x) __builtin_expect(!!(x), 0) @@ -101,13 +98,21 @@ #define trace3(...) #endif -#include -#define IOMATRIX_SIZE 64 +#include "picohttpparser-git/picohttpparser.c" +#include "rinq.c" + +// Check FEERSUM_IOMATRIX_SIZE against what's actually usable on this +// platform. See $iomatrix_size in Makefile.PL for the default. +#if FEERSUM_IOMATRIX_SIZE > IOV_MAX +# undef FEERSUM_IOMATRIX_SIZE +# define FEERSUM_IOMATRIX_SIZE IOV_MAX +#endif + struct iomatrix { unsigned offset; unsigned count; - struct iovec iov[IOMATRIX_SIZE]; - SV *sv[IOMATRIX_SIZE]; + struct iovec iov[FEERSUM_IOMATRIX_SIZE]; + SV *sv[FEERSUM_IOMATRIX_SIZE]; }; struct feer_req { @@ -2613,4 +2618,15 @@ BOOT: Zero(&psgix_io_vtbl, 1, MGVTBL); psgix_io_vtbl.svt_get = psgix_io_svt_get; + + trace3("Feersum booted, iomatrix %lu " + "(IOV_MAX=%u, FEERSUM_IOMATRIX_SIZE=%u), " + "feer_req %lu, " + "feer_conn %lu\n", + (long unsigned int)sizeof(struct iomatrix), + (unsigned int)IOV_MAX, + (unsigned int)FEERSUM_IOMATRIX_SIZE, + (long unsigned int)sizeof(struct feer_req), + (long unsigned int)sizeof(struct feer_conn) + ); } diff --git a/Makefile.PL b/Makefile.PL index 7b147bd..e8efe02 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -58,6 +58,17 @@ if ($convert_deps) { use Config; my $steal = ($] >= 5.012 && !defined($Config{useithreads})); +# Control the size of the main write-buffer structure in feersum. Making this +# value lower will use slightly less memory per connection at the cost of +# speed and vice-versa. It's most noticeable when you're app is buffering a +# lot of sparce writes. The default of 64 generally keeps usage under 4k per +# connection on full 64-bit when you take into account the other connection +# and request structures. +# NOTE: If your OS defines IOV_MAX or UIO_MAXIOV then this value will be +# forced to be at most that size with a #define. Solaris defines IOV_MAX to +# be 16. Linux and OSX generally have IOV_MAX as 1024. +my $iomatrix_size = 64; + WriteMakefile(ev_args( NAME => 'Feersum', VERSION_FROM => 'lib/Feersum.pm', @@ -92,7 +103,8 @@ WriteMakefile(ev_args( }, LIBS => [''], EXE_FILES => ['bin/feersum'], - DEFINE => ($steal ? '-DFEERSUM_STEAL' : ''), + DEFINE => "-DFEERSUM_IOMATRIX_SIZE=$iomatrix_size ". + ($steal ? '-DFEERSUM_STEAL' : ''), INC => '-I.', dynamic_lib => {OTHERLDFLAGS => $otherldflags}, ));