forked from lda/telodendria
Add max-cache option to the config file
This commit is contained in:
parent
d32742bb25
commit
624b080d47
8 changed files with 84 additions and 6 deletions
|
@ -15,3 +15,4 @@ log "stdout" {
|
|||
};
|
||||
threads "4";
|
||||
max-connections "32";
|
||||
max-cache "1k";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Telodendria production configuration file.
|
||||
# Telodendria configuration file.
|
||||
#
|
||||
# The following man pages document the configuration:
|
||||
#
|
||||
|
@ -26,5 +26,7 @@ log "file" {
|
|||
level "warning";
|
||||
timestampFormat "default";
|
||||
};
|
||||
|
||||
threads "4";
|
||||
max-connections "32";
|
||||
max-cache "512M";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.Dd $Mdocdate: October 15 2022 $
|
||||
.Dd $Mdocdate: October 24 2022 $
|
||||
.Dt TELODENDRIA.CONF 5
|
||||
.Os Telodendria Project
|
||||
.Sh NAME
|
||||
|
@ -172,6 +172,17 @@ less than the total CPU core count, to prevent overloading the system. The most
|
|||
efficient number of threads ultimately depends on the configuration of the
|
||||
machine running Telodendria, so you may just have to play around with different
|
||||
values here to see which gives the best performance.
|
||||
.It Ic max-connections Ar count
|
||||
The maximum number of simultanious connections to allow to the daemon. This option
|
||||
prevents the daemon from allocating large amounts of memory in the even that it
|
||||
undergoes a denial of service attack. It typically does not need to be adjusted.
|
||||
.It Ic max-cache Ar bytes
|
||||
The maximum size of the cache. Telodendria relies heavily on caching to speed
|
||||
things up. The cache grows as data is loaded from the data directory. All cache
|
||||
is stored in memory. This option limits the size of the memory cache. If you have
|
||||
a system that has a lot of memory, you'll get better performance if this option
|
||||
is set higher. Otherwise, this value should be lowered on systems that have
|
||||
minimal memory available.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width Ds
|
||||
|
|
|
@ -334,6 +334,8 @@ main(int argc, char **argv)
|
|||
Log(lc, LOG_DEBUG, "Run As: %s:%s", tConfig->uid, tConfig->gid);
|
||||
Log(lc, LOG_DEBUG, "Data Directory: %s", tConfig->dataDir);
|
||||
Log(lc, LOG_DEBUG, "Threads: %d", tConfig->threads);
|
||||
Log(lc, LOG_DEBUG, "Max Connections: %d", tConfig->maxConnections);
|
||||
Log(lc, LOG_DEBUG, "Max Cache: %ld", tConfig->maxCache);
|
||||
Log(lc, LOG_DEBUG, "Flags: %x", tConfig->flags);
|
||||
LogConfigUnindent(lc);
|
||||
|
||||
|
|
|
@ -230,7 +230,10 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
GET_DIRECTIVE("max-cache");
|
||||
ASSERT_NO_CHILDREN("max-cache");
|
||||
ASSERT_VALUES("max-cache", 1);
|
||||
tConfig->maxCache = UtilStringToBytes(ArrayGet(value, 0));
|
||||
|
||||
GET_DIRECTIVE("federation");
|
||||
ASSERT_NO_CHILDREN("federation");
|
||||
|
|
56
src/Util.c
56
src/Util.c
|
@ -27,14 +27,16 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
long
|
||||
unsigned long
|
||||
UtilServerTs(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
long ts;
|
||||
unsigned long ts;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
ts = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
|
@ -122,3 +124,53 @@ UtilSleepMillis(long ms)
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t
|
||||
UtilStringToBytes(char *str)
|
||||
{
|
||||
size_t bytes = 0;
|
||||
|
||||
while (*str)
|
||||
{
|
||||
if (isdigit(*str))
|
||||
{
|
||||
bytes *= 10;
|
||||
bytes += *str - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (*str)
|
||||
{
|
||||
case 'K':
|
||||
bytes *= 1024;
|
||||
break;
|
||||
case 'M':
|
||||
bytes *= pow(1024, 2);
|
||||
break;
|
||||
case 'G':
|
||||
bytes *= pow(1024, 3);
|
||||
break;
|
||||
case 'k':
|
||||
bytes *= 1000;
|
||||
break;
|
||||
case 'm':
|
||||
bytes *= pow(1000, 2);
|
||||
break;
|
||||
case 'g':
|
||||
bytes *= pow(1000, 3);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*(str + 1))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
str++;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
|
|
@ -68,6 +68,8 @@ typedef struct TelodendriaConfig
|
|||
unsigned int threads;
|
||||
unsigned int maxConnections;
|
||||
|
||||
size_t maxCache;
|
||||
|
||||
char *logTimestamp;
|
||||
int logLevel;
|
||||
} TelodendriaConfig;
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#ifndef TELODENDRIA_UTIL_H
|
||||
#define TELODENDRIA_UTIL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* Get the current type in milliseconds since the Unix epoch. This uses
|
||||
* POSIX gettimeofday(2) and time_t, and converts it to a single number,
|
||||
|
@ -50,7 +52,7 @@
|
|||
* Return: A long representing the current time in milliseconds since
|
||||
* the beginning of the Unix epoch, just as the Matrix spec requires.
|
||||
*/
|
||||
extern long
|
||||
extern unsigned long
|
||||
UtilServerTs(void);
|
||||
|
||||
/*
|
||||
|
@ -96,4 +98,7 @@ extern char *
|
|||
extern int
|
||||
UtilSleepMillis(long);
|
||||
|
||||
extern size_t
|
||||
UtilStringToBytes(char *);
|
||||
|
||||
#endif /* TELODENDRIA_UTIL_H */
|
||||
|
|
Loading…
Reference in a new issue