mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
sync
This commit is contained in:
parent
c6a85f2261
commit
ab56ae55a7
|
@ -6,7 +6,6 @@ TechEmpower Web Framework Benchmarks
|
|||
#include "world.h"
|
||||
|
||||
static World* pworld_update;
|
||||
static UString* pquery;
|
||||
static UOrmSession* psql_update;
|
||||
static UOrmStatement* pstmt;
|
||||
static UVector<World*>* pvworld_update;
|
||||
|
@ -33,8 +32,6 @@ static void usp_fork_update()
|
|||
pstmt->use( pworld_update->id);
|
||||
pstmt->into(pworld_update->randomNumber);
|
||||
|
||||
U_NEW(UString, pquery, UString(U_CAPACITY));
|
||||
|
||||
U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
|
||||
}
|
||||
|
||||
|
@ -48,7 +45,6 @@ static void usp_end_update()
|
|||
if (pstmt)
|
||||
{
|
||||
delete pstmt;
|
||||
delete pquery;
|
||||
delete pworld_update;
|
||||
delete pvworld_update;
|
||||
}
|
||||
|
@ -61,7 +57,7 @@ Content-Type: application/json
|
|||
<!--#code
|
||||
char* ptr;
|
||||
World* pworld;
|
||||
char* query = pquery->data();
|
||||
char query[8192];
|
||||
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
|
||||
|
||||
(void) memcpy(query, "UPDATE World SET randomNumber = v.randomNumber FROM (VALUES",
|
||||
|
@ -83,7 +79,7 @@ while (true)
|
|||
if (++i == num_queries) break;
|
||||
}
|
||||
|
||||
pvworld_update->sort();
|
||||
pvworld_update->sort(World::cmp_obj);
|
||||
|
||||
#ifdef AS_cpoll_cppsp_DO
|
||||
USP_PUTS_CHAR('[');
|
||||
|
@ -99,8 +95,7 @@ while (true)
|
|||
|
||||
ptr = u_num2str32(pworld->id, ptr);
|
||||
|
||||
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16(',',' '));
|
||||
ptr += 2;
|
||||
*ptr++ = ',';
|
||||
|
||||
ptr = u_num2str32(pworld->randomNumber, ptr);
|
||||
|
||||
|
@ -120,12 +115,14 @@ while (true)
|
|||
|
||||
#ifdef AS_cpoll_cppsp_DO
|
||||
USP_PUTS_CHAR(']');
|
||||
#else
|
||||
USP_OBJ_JSON_stringify(*pvworld_update);
|
||||
#endif
|
||||
|
||||
(void) memcpy(ptr-1, ") AS v (id, randomNumber) WHERE World.id = v.id;",
|
||||
U_CONSTANT_SIZE(") AS v (id, randomNumber) WHERE World.id = v.id;")+1);
|
||||
|
||||
*psql_update << query;
|
||||
|
||||
pvworld_update->clear();
|
||||
|
||||
(void) memcpy(ptr-1, ") AS v (id,randomNumber) WHERE World.id = v.id;",
|
||||
U_CONSTANT_SIZE(") AS v (id,randomNumber) WHERE World.id = v.id;")+1);
|
||||
|
||||
if (psql_update->query(query, ptr + U_CONSTANT_SIZE(") AS v (id,randomNumber) WHERE World.id = v.id;") - query) == false) UHTTP::setInternalError();
|
||||
-->
|
||||
|
|
|
@ -1127,7 +1127,7 @@ UThread* UServer_Base::pthread_ocsp;
|
|||
* - The IP address of the requestor is hashed into a "key". A lookup is performed in the listener's internal hash table to determine if
|
||||
* the same host has requested more than 50 objects within the past second.
|
||||
* - The IP address of the requestor and the URI are both hashed into a "key". A lookup is performed in the listener's internal hash table
|
||||
* to determine if the same host has requested this page more than 3 within the past 1 second.
|
||||
* to determine if the same host has requested this page more than 5 within the past 1 second.
|
||||
*
|
||||
* If any of the above are true, a RESET is sent. This conserves bandwidth and system resources in the event of a DoS attack. Additionally,
|
||||
* a system command and/or an email notification can also be triggered to block all the originating addresses of a DDoS attack.
|
||||
|
@ -1225,10 +1225,14 @@ void UServer_Base::initEvasive()
|
|||
U_INTERNAL_ASSERT_POINTER(ptr_shared_data)
|
||||
U_INTERNAL_ASSERT_DIFFERS(ptr_shared_data, MAP_FAILED)
|
||||
|
||||
# ifdef USE_LIBSSL
|
||||
db_evasive->setShared(U_NULLPTR, U_NULLPTR); // POSIX shared memory object (interprocess - can be used by unrelated processes (userver_tcp and userver_ssl)
|
||||
# else
|
||||
db_evasive->setShared(U_SRV_LOCK_EVASIVE, U_SRV_SPINLOCK_EVASIVE);
|
||||
# endif
|
||||
}
|
||||
|
||||
bool result = db_evasive->open(1024 * 1024, false, true); // NB: we don't want truncate (we have only the journal)...
|
||||
bool result = db_evasive->open(4096 * 4096, false, true); // NB: we don't want truncate (we have only the journal)...
|
||||
|
||||
U_SRV_LOG("%sdb initialization of Evasive %s: size(%u)", (result ? "" : "WARNING: "), (result ? "success" : "failed"), db_evasive->size());
|
||||
|
||||
|
@ -1297,8 +1301,8 @@ bool UServer_Base::checkHitStats(const char* key, uint32_t key_len, uint32_t int
|
|||
{
|
||||
char msg[256];
|
||||
uint32_t msg_len = (count == site_count
|
||||
? u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("it has requested more than %u objects within the past %u seconds"), site_count, site_interval)
|
||||
: u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("it has requested the same page more than %u within the past %u seconds"), page_count, page_interval));
|
||||
? u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("it has requested more than %u objects within the past %u seconds"), site_count, site_interval)
|
||||
: u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("it has requested the same page more than %u within the past %u seconds"), page_count, page_interval));
|
||||
|
||||
evasive_rec->count = 0;
|
||||
evasive_rec->timestamp = u_now->tv_sec;
|
||||
|
@ -1375,12 +1379,12 @@ bool UServer_Base::checkHitStats(const char* key, uint32_t key_len, uint32_t int
|
|||
emailClient->setMessageSubject(U_STRING_FROM_CONSTANT("possible DoS attack"));
|
||||
|
||||
# ifdef USE_LIBSSL
|
||||
bool ok = emailClient->sendMessage(true);
|
||||
bool bsecure = true;
|
||||
# else
|
||||
bool ok = emailClient->sendMessage(false);
|
||||
bool bsecure = false;
|
||||
# endif
|
||||
|
||||
if (ok == false)
|
||||
if (emailClient->sendMessage(bsecure) == false)
|
||||
{
|
||||
emailClient->setStatus();
|
||||
|
||||
|
@ -2085,10 +2089,10 @@ void UServer_Base::loadConfigParam()
|
|||
#ifdef U_EVASIVE_SUPPORT
|
||||
/**
|
||||
* This is the threshhold for the number of requests for the same page (or URI) per page interval.
|
||||
* Once the threshhold for that interval has been exceeded (defaults to 3), the IP address of the client will be added to the blocking list
|
||||
* Once the threshhold for that interval has been exceeded (defaults to 5), the IP address of the client will be added to the blocking list
|
||||
*/
|
||||
|
||||
page_count = cfg->readLong(U_CONSTANT_TO_PARAM("DOS_PAGE_COUNT"), 3);
|
||||
page_count = cfg->readLong(U_CONSTANT_TO_PARAM("DOS_PAGE_COUNT"), 5);
|
||||
|
||||
/**
|
||||
* The interval for the page count threshhold; defaults to 1 second intervals
|
||||
|
|
|
@ -17,7 +17,7 @@ sed -i "s|CLIENT_FOR_PARALLELIZATION .*|CLIENT_FOR_PARALLELIZATION 100|g" $IROOT
|
|||
|
||||
# 2. Start ULib Server (userver_tcp)
|
||||
export ORM_DRIVER="mysql"
|
||||
export UMEMPOOL="545,0,0,49,275,-14,-13,-25,41"
|
||||
export UMEMPOOL="750,0,123,251,305,53,-6,-26,52"
|
||||
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=hello_world"
|
||||
|
||||
# Never use setcap inside of TRAVIS
|
||||
|
|
|
@ -12,7 +12,7 @@ sed -i "s|CLIENT_FOR_PARALLELIZATION .*|CLIENT_FOR_PARALLELIZATION 100|g" $IROOT
|
|||
|
||||
# 2. Start ULib Server (userver_tcp)
|
||||
export ORM_DRIVER="pgsql"
|
||||
export UMEMPOOL="545,0,0,41,275,-14,-13,-25,41"
|
||||
export UMEMPOOL="750,0,123,251,305,53,-6,-26,52"
|
||||
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world client_encoding=UTF8"
|
||||
|
||||
# Never use setcap inside of TRAVIS
|
||||
|
|
|
@ -17,7 +17,7 @@ sed -i "s|CLIENT_FOR_PARALLELIZATION .*|CLIENT_FOR_PARALLELIZATION 100|g" $IROOT
|
|||
|
||||
# 2. Start ULib Server (userver_tcp)
|
||||
export ORM_DRIVER="sqlite"
|
||||
export UMEMPOOL="545,0,0,49,275,-14,-13,-25,41"
|
||||
export UMEMPOOL="750,0,123,251,305,53,-6,-26,52"
|
||||
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=${IROOT}/ULib/db/%.*s"
|
||||
|
||||
# Never use setcap inside of TRAVIS
|
||||
|
|
|
@ -6,7 +6,6 @@ TechEmpower Web Framework Benchmarks
|
|||
#include "world.h"
|
||||
|
||||
static World* pworld_update;
|
||||
static UString* pquery;
|
||||
static UOrmSession* psql_update;
|
||||
static UOrmStatement* pstmt;
|
||||
static UVector<World*>* pvworld_update;
|
||||
|
@ -33,8 +32,6 @@ static void usp_fork_update()
|
|||
pstmt->use( pworld_update->id);
|
||||
pstmt->into(pworld_update->randomNumber);
|
||||
|
||||
U_NEW(UString, pquery, UString(U_CAPACITY));
|
||||
|
||||
U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
|
||||
}
|
||||
|
||||
|
@ -48,7 +45,6 @@ static void usp_end_update()
|
|||
if (pstmt)
|
||||
{
|
||||
delete pstmt;
|
||||
delete pquery;
|
||||
delete pworld_update;
|
||||
delete pvworld_update;
|
||||
}
|
||||
|
@ -61,7 +57,7 @@ Content-Type: application/json
|
|||
<!--#code
|
||||
char* ptr;
|
||||
World* pworld;
|
||||
char* query = pquery->data();
|
||||
char query[8192];
|
||||
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
|
||||
|
||||
(void) memcpy(query, "UPDATE World SET randomNumber = v.randomNumber FROM (VALUES",
|
||||
|
@ -83,7 +79,7 @@ while (true)
|
|||
if (++i == num_queries) break;
|
||||
}
|
||||
|
||||
pvworld_update->sort();
|
||||
pvworld_update->sort(World::cmp_obj);
|
||||
|
||||
#ifdef AS_cpoll_cppsp_DO
|
||||
USP_PUTS_CHAR('[');
|
||||
|
@ -99,8 +95,7 @@ while (true)
|
|||
|
||||
ptr = u_num2str32(pworld->id, ptr);
|
||||
|
||||
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16(',',' '));
|
||||
ptr += 2;
|
||||
*ptr++ = ',';
|
||||
|
||||
ptr = u_num2str32(pworld->randomNumber, ptr);
|
||||
|
||||
|
@ -120,12 +115,14 @@ while (true)
|
|||
|
||||
#ifdef AS_cpoll_cppsp_DO
|
||||
USP_PUTS_CHAR(']');
|
||||
#else
|
||||
USP_OBJ_JSON_stringify(*pvworld_update);
|
||||
#endif
|
||||
|
||||
(void) memcpy(ptr-1, ") AS v (id, randomNumber) WHERE World.id = v.id;",
|
||||
U_CONSTANT_SIZE(") AS v (id, randomNumber) WHERE World.id = v.id;")+1);
|
||||
|
||||
*psql_update << query;
|
||||
|
||||
pvworld_update->clear();
|
||||
|
||||
(void) memcpy(ptr-1, ") AS v (id,randomNumber) WHERE World.id = v.id;",
|
||||
U_CONSTANT_SIZE(") AS v (id,randomNumber) WHERE World.id = v.id;")+1);
|
||||
|
||||
if (psql_update->query(query, ptr + U_CONSTANT_SIZE(") AS v (id,randomNumber) WHERE World.id = v.id;") - query) == false) UHTTP::setInternalError();
|
||||
-->
|
||||
|
|
|
@ -17,7 +17,8 @@ rm -f tmp/usp_compile.sh.err /tmp/*.hpack.* \
|
|||
UTRACE_SIGNAL="0 50M -1"
|
||||
#UOBJDUMP="0 10M 100"
|
||||
#USIMERR="error.sim"
|
||||
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL
|
||||
UMEMUSAGE=yes
|
||||
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE
|
||||
|
||||
SOCK1=tmp/fcgi.socket
|
||||
|
||||
|
@ -98,7 +99,7 @@ EOF
|
|||
|
||||
export ORM_DRIVER="sqlite"
|
||||
export ELASTICSEARCH_HOST="localhost"
|
||||
export UMEMPOOL="136,0,60,100,250,-22,-17,-23,60"
|
||||
export UMEMPOOL="750,0,123,251,305,53,-6,-26,52"
|
||||
#export ORM_OPTION="host=localhost dbname=../db/fortune"
|
||||
export ORM_OPTION="host=localhost dbname=../db/hello_world"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user