Skip to content

Commit

Permalink
load balance implementation
Browse files Browse the repository at this point in the history
stefanocasazza committed Feb 24, 2017
1 parent 96de41f commit fee5d2b
Showing 82 changed files with 2,039 additions and 1,094 deletions.
39 changes: 30 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1054,6 +1054,7 @@ enable_ACL
enable_RFC1918
enable_HSTS
enable_HPS
enable_load_balance
with_parser
with_distcc
with_libz
@@ -1796,6 +1797,7 @@ Optional Features:
--enable-RFC1918 enable RFC1918 filtering support [default=no]
--enable-HSTS enable HTTP Strict Transport Security support [default=no]
--enable-HPS enable HTML Pagination Support [default=no]
--enable-load-balance enable load balance support between physical server via udp brodcast [default=no]
--enable-zip enable build of ZIP support - require libz [default: use if present libz]
--enable-ssl-staticlib-deps link with dependencies of OpenSSL's static libraries. Must be specified in addition to --with-ssl [default=no]
--enable-curl-staticlib-deps link with dependencies of cURL's static libraries. Must be specified in addition to --with-curl [default=no]
@@ -26593,6 +26595,24 @@ $as_echo "#define U_HTML_PAGINATION_SUPPORT 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_HPS" >&5
$as_echo "$enable_HPS" >&6; }

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if you want to enable load balance support between physical server via udp brodcast" >&5
$as_echo_n "checking if you want to enable load balance support between physical server via udp brodcast... " >&6; }
# Check whether --enable-load-balance was given.
if test "${enable_load_balance+set}" = set; then :
enableval=$enable_load_balance;
fi

if test -z "$enable_load_balance"; then
enable_load_balance="no"
fi
if test "$enable_load_balance" = "yes"; then

$as_echo "#define USE_LOAD_BALANCE 1" >>confdefs.h

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_load_balance" >&5
$as_echo "$enable_load_balance" >&6; }


# SECTION 3: check for programs

@@ -36605,14 +36625,14 @@ if test -n "$AWK"; then
cd ../../..
fi

# Verify the integrity of the current configuration

echo
echo "***"

CPPFLAGS="-DHAVE_CONFIG_H -I${srcdir}/include $CPPFLAGS"
# Verify the integrity of the current configuration
if test "$cross_compiling" != "yes"; then
CPPFLAGS="-DHAVE_CONFIG_H -I${srcdir}/include $CPPFLAGS"

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if generated configuration is usable" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if generated configuration is usable" >&5
$as_echo_n "checking if generated configuration is usable... " >&6; }
if ${ac_cv_configuration_is_usable+:} false; then :
$as_echo_n "(cached) " >&6
@@ -36641,11 +36661,12 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_configuration_is_usable" >&5
$as_echo "$ac_cv_configuration_is_usable" >&6; }

if test "$ac_cv_configuration_is_usable" = "no" ; then
# It appears that ulib/internal/common.cpp not compiled. If it didn't compile then there would be no chance that the rest would compile.
as_fn_error $? "The generated configuration appears to be unusable.
Please verify that your system path and environment variables are correct." "$LINENO" 5
exit 1
if test "$ac_cv_configuration_is_usable" = "no" ; then
# It appears that ulib/internal/common.cpp not compiled. If it didn't compile then there would be no chance that the rest would compile.
as_fn_error $? "The generated configuration appears to be unusable.
Please verify that your system path and environment variables are correct." "$LINENO" 5
exit 1
fi
fi

echo
19 changes: 10 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -2744,24 +2744,25 @@ if test -n "$AWK"; then
cd ../../..
fi

# Verify the integrity of the current configuration

echo
echo "***"

CPPFLAGS="-DHAVE_CONFIG_H -I${srcdir}/include $CPPFLAGS"
# Verify the integrity of the current configuration
if test "$cross_compiling" != "yes"; then
CPPFLAGS="-DHAVE_CONFIG_H -I${srcdir}/include $CPPFLAGS"

AC_CACHE_CHECK([if generated configuration is usable], ac_cv_configuration_is_usable,
AC_CACHE_CHECK([if generated configuration is usable], ac_cv_configuration_is_usable,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "src/ulib/internal/common.cpp"
]], [[int a = 0; a += 1;]])],[ac_cv_configuration_is_usable="yes"],[ac_cv_configuration_is_usable="no"])
])

if test "$ac_cv_configuration_is_usable" = "no" ; then
# It appears that ulib/internal/common.cpp not compiled. If it didn't compile then there would be no chance that the rest would compile.
AC_MSG_ERROR([The generated configuration appears to be unusable.
Please verify that your system path and environment variables are correct.])
exit 1
if test "$ac_cv_configuration_is_usable" = "no" ; then
# It appears that ulib/internal/common.cpp not compiled. If it didn't compile then there would be no chance that the rest would compile.
AC_MSG_ERROR([The generated configuration appears to be unusable.
Please verify that your system path and environment variables are correct.])
exit 1
fi
fi

echo
4 changes: 2 additions & 2 deletions fuzz/Makefile.am
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ DEFAULT_INCLUDES = -I. -I$(top_srcdir)/include
uclient_fuzzer_CC = clang
uclient_fuzzer_CXX = clang++
uclient_fuzzer_CPPFLAGS = -D_GLIBCXX_GCC_GTHR_H
uclient_fuzzer_SOURCES = uclient_fuzzer.cpp
uclient_fuzzer_LDADD = $(ulib_la) libFuzzer.a
uclient_fuzzer_CFLAGS = -fno-omit-frame-pointer -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters
uclient_fuzzer_CXXFLAGS = -fno-omit-frame-pointer -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters
uclient_fuzzer_LDFLAGS = -fsanitize=address
uclient_fuzzer_SOURCES = uclient_fuzzer.cpp
uclient_fuzzer_LDADD = $(ulib_la) libFuzzer.a

if CLANG
noinst_PROGRAMS = uclient_fuzzer
4 changes: 2 additions & 2 deletions fuzz/Makefile.in
Original file line number Diff line number Diff line change
@@ -382,11 +382,11 @@ DEFAULT_INCLUDES = -I. -I$(top_srcdir)/include
uclient_fuzzer_CC = clang
uclient_fuzzer_CXX = clang++
uclient_fuzzer_CPPFLAGS = -D_GLIBCXX_GCC_GTHR_H
uclient_fuzzer_SOURCES = uclient_fuzzer.cpp
uclient_fuzzer_LDADD = $(ulib_la) libFuzzer.a
uclient_fuzzer_CFLAGS = -fno-omit-frame-pointer -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters
uclient_fuzzer_CXXFLAGS = -fno-omit-frame-pointer -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters
uclient_fuzzer_LDFLAGS = -fsanitize=address
uclient_fuzzer_SOURCES = uclient_fuzzer.cpp
uclient_fuzzer_LDADD = $(ulib_la) libFuzzer.a
all: all-am

.SUFFIXES:
2 changes: 1 addition & 1 deletion fuzz/build_libFuzzer.sh
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
[ -e libFuzzer.a ] && exit 0
[ -d Fuzzer ] || git clone https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer
cd Fuzzer
git checkout 29d1659edabe4ba2396f9697915bb7a0880cbd2f
#git checkout 29d1659edabe4ba2396f9697915bb7a0880cbd2f
cd ..
Fuzzer/build.sh
41 changes: 10 additions & 31 deletions include/ulib/base/utility.h
Original file line number Diff line number Diff line change
@@ -303,37 +303,16 @@ static inline bool u_dosmatch_ext_with_OR(const char* restrict s, uint32_t n1, c
return u_match_with_OR(u_dosmatch_ext, s, n1, pattern, n2, flags);
}

/* Change the current working directory to the `user` user's home dir, and downgrade security to that user account */

U_EXPORT bool u_runAsUser(const char* restrict user, bool change_dir);

/* Verifies that the passed string is actually an e-mail address */

U_EXPORT bool u_validate_email_address(const char* restrict address, uint32_t address_len) __pure;

/* Perform 'natural order' comparisons of strings. */

U_EXPORT int u_strnatcmp(char const* restrict a, char const* restrict b) __pure;

/* Get address space and rss (resident set size) usage */

U_EXPORT void u_get_memusage(unsigned long* vsz, unsigned long* rss);

/* Get the uptime of the system (seconds) */

U_EXPORT uint32_t u_get_uptime(void);

/* Get the number of the processors including offline CPUs */

U_EXPORT int u_get_num_cpu(void);

/* Pin the process to a particular core */

U_EXPORT void u_bind2cpu(cpu_set_t* cpuset, int n);

/* Set the process to maximum priority that can be used with the scheduling algorithm */

U_EXPORT void u_switch_to_realtime_priority(void);
U_EXPORT uint8_t u_get_loadavg(void); /* Get the load average of the system (over last 1 minute) */
U_EXPORT uint32_t u_get_uptime(void); /* Get the uptime of the system (seconds) */

U_EXPORT int u_get_num_cpu(void); /* Get the number of the processors including offline CPUs */
U_EXPORT int u_strnatcmp(char const* restrict a, char const* restrict b) __pure; /* Perform 'natural order' comparisons of strings. */
U_EXPORT void u_switch_to_realtime_priority(void); /* Set the process to maximum priority that can be used with the scheduling algorithm */
U_EXPORT void u_bind2cpu(cpu_set_t* cpuset, int n); /* Pin the process to a particular core */
U_EXPORT void u_get_memusage(unsigned long* vsz, unsigned long* rss); /* Get address space and rss (resident set size) usage */
U_EXPORT bool u_runAsUser(const char* restrict user, bool change_dir); /* Change the current working directory to the `user` user's home dir, and downgrade security to that user account */
U_EXPORT bool u_validate_email_address(const char* restrict address, uint32_t address_len) __pure; /* Verifies that the passed string is actually an e-mail address */

/**
* Canonicalize PATH, and build a new path. The new path differs from PATH in that:
56 changes: 31 additions & 25 deletions include/ulib/container/gen_hash_map.h
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@

#include <ulib/internal/common.h>

class UNotifier;

/**
* Functor used by UGenericHashMap class to generate a hashcode for an object of type T. It must be specialized for your own class
*/
@@ -107,31 +109,6 @@ template <typename K, typename I,
U_TRACE_UNREGISTER_OBJECT(0, UGenericHashMap)
}

// Allocate and deallocate methods

void allocate(uint32_t n = 53)
{
U_TRACE(0, "UGenericHashMap<K,I>::allocate(%u)", n)

U_CHECK_MEMORY

table = (UGenericHashMapNode**) UMemoryPool::_malloc(&n, sizeof(UGenericHashMapNode*), true);
_capacity = n;
}

void deallocate()
{
U_TRACE_NO_PARAM(0, "UGenericHashMap<K,I>::deallocate()")

U_CHECK_MEMORY

U_INTERNAL_ASSERT_MAJOR(_capacity,0)

UMemoryPool::_free(table, _capacity, sizeof(UGenericHashMapNode*));

_capacity = 0;
}

// Size and capacity

uint32_t size() const
@@ -504,6 +481,33 @@ template <typename K, typename I,
}
#endif

protected:
// allocate and deallocate methods

void allocate(uint32_t n = 53)
{
U_TRACE(0, "UGenericHashMap<K,I>::allocate(%u)", n)

U_CHECK_MEMORY

table = (UGenericHashMapNode**) UMemoryPool::_malloc(&n, sizeof(UGenericHashMapNode*), true);
_capacity = n;
}

void deallocate()
{
U_TRACE_NO_PARAM(0, "UGenericHashMap<K,I>::deallocate()")

U_CHECK_MEMORY

U_INTERNAL_ASSERT_MAJOR(_capacity,0)

UMemoryPool::_free(table, _capacity, sizeof(UGenericHashMapNode*));

_capacity = 0;
}


private:
#ifdef U_COMPILER_DELETE_MEMBERS
UGenericHashMap(const UGenericHashMap&) = delete;
@@ -516,6 +520,8 @@ template <typename K, typename I,
template<typename A, typename B, typename C, typename D> UGenericHashMap(const UGenericHashMap<A,B,C,D>&) {}
template<typename A, typename B, typename C, typename D> UGenericHashMap& operator=(const UGenericHashMap<A,B,C,D>&) { return *this; }
#endif

friend class UNotifier;
};

// Functor used by UGenericHashMap class to generate a hashcode for an object of type <int>
35 changes: 18 additions & 17 deletions include/ulib/container/hash_map.h
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ typedef bool (*bPFptpcu) (UHashMap<void*>*,const char*,uint32_t);
class UCDB;
class UHTTP;
class UHTTP2;
class UDirWalk;
class WeightWord;
class UMimeHeader;
class UFileConfig;
@@ -116,22 +117,6 @@ template <> class U_EXPORT UHashMap<void*> {
if (_capacity) _deallocate();
}

// allocate and deallocate methods

void deallocate()
{
U_TRACE_NO_PARAM(0, "UHashMap<void*>::deallocate()")

if (_capacity)
{
_deallocate();

_capacity = 0;
}
}

void allocate(uint32_t n);

// size and capacity

uint32_t size() const
@@ -252,7 +237,8 @@ template <> class U_EXPORT UHashMap<void*> {

// make room for a total of n element

void reserve(uint32_t n);
void reserve( uint32_t n);
void allocate(uint32_t n);

// Traverse the hash table for all entry

@@ -304,6 +290,8 @@ template <> class U_EXPORT UHashMap<void*> {
bool check_memory() const; // check all element
#endif

// allocate and deallocate methods

void _allocate(uint32_t n)
{
U_TRACE(0, "UHashMap<void*>::_allocate(%u)", n)
@@ -325,6 +313,18 @@ template <> class U_EXPORT UHashMap<void*> {
UMemoryPool::_free(table, _capacity, sizeof(UHashMapNode*));
}

void deallocate()
{
U_TRACE_NO_PARAM(0, "UHashMap<void*>::deallocate()")

if (_capacity)
{
_deallocate();

_capacity = 0;
}
}

void init(uint32_t n)
{
U_TRACE(0, "UHashMap<void*>::init(%u)", n)
@@ -406,6 +406,7 @@ template <> class U_EXPORT UHashMap<void*> {
friend class UHTTP2;
friend class UValue;
friend class UString;
friend class UDirWalk;
friend class WeightWord;
friend class UFileConfig;
friend class UCertificate;
Loading

0 comments on commit fee5d2b

Please sign in to comment.