mirror of https://github.com/F-Stack/f-stack.git
reset cpu affinity when new process forked.
New forked process should not compete same core with redis server.
This commit is contained in:
parent
dc5b2a9e54
commit
9518765b1f
|
@ -1272,6 +1272,7 @@ int rewriteAppendOnlyFileBackground(void) {
|
||||||
|
|
||||||
/* Child */
|
/* Child */
|
||||||
closeListeningSockets(0);
|
closeListeningSockets(0);
|
||||||
|
resetCpuAffinity("aof-rewrite");
|
||||||
redisSetProcTitle("redis-aof-rewrite");
|
redisSetProcTitle("redis-aof-rewrite");
|
||||||
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
|
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
|
||||||
if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
|
if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
|
||||||
|
|
|
@ -930,6 +930,7 @@ int rdbSaveBackground(char *filename) {
|
||||||
|
|
||||||
/* Child */
|
/* Child */
|
||||||
closeListeningSockets(0);
|
closeListeningSockets(0);
|
||||||
|
resetCpuAffinity("rdb-bgsave");
|
||||||
redisSetProcTitle("redis-rdb-bgsave");
|
redisSetProcTitle("redis-rdb-bgsave");
|
||||||
retval = rdbSave(filename);
|
retval = rdbSave(filename);
|
||||||
if (retval == C_OK) {
|
if (retval == C_OK) {
|
||||||
|
@ -1631,6 +1632,7 @@ int rdbSaveToSlavesSockets(void) {
|
||||||
zfree(fds);
|
zfree(fds);
|
||||||
|
|
||||||
closeListeningSockets(0);
|
closeListeningSockets(0);
|
||||||
|
resetCpuAffinity("rdb2slave");
|
||||||
redisSetProcTitle("redis-rdb-to-slaves");
|
redisSetProcTitle("redis-rdb-to-slaves");
|
||||||
|
|
||||||
retval = rdbSaveRioWithEOFMark(&slave_sockets,NULL);
|
retval = rdbSaveRioWithEOFMark(&slave_sockets,NULL);
|
||||||
|
|
|
@ -1611,6 +1611,7 @@ int ldbStartSession(client *c) {
|
||||||
* to the clients. */
|
* to the clients. */
|
||||||
serverLog(LL_WARNING,"Redis forked for debugging eval");
|
serverLog(LL_WARNING,"Redis forked for debugging eval");
|
||||||
closeListeningSockets(0);
|
closeListeningSockets(0);
|
||||||
|
resetCpuAffinity("redis-dbg");
|
||||||
} else {
|
} else {
|
||||||
/* Parent */
|
/* Parent */
|
||||||
listAddNodeTail(ldb.children,(void*)(unsigned long)cp);
|
listAddNodeTail(ldb.children,(void*)(unsigned long)cp);
|
||||||
|
|
|
@ -763,6 +763,7 @@ void sentinelRunPendingScripts(void) {
|
||||||
sj->pid = 0;
|
sj->pid = 0;
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
/* Child */
|
/* Child */
|
||||||
|
resetCpuAffinity(NULL);
|
||||||
execve(sj->argv[0],sj->argv,environ);
|
execve(sj->argv[0],sj->argv,environ);
|
||||||
/* If we are here an error occurred. */
|
/* If we are here an error occurred. */
|
||||||
_exit(2); /* Don't retry execution. */
|
_exit(2); /* Don't retry execution. */
|
||||||
|
|
|
@ -2558,6 +2558,36 @@ void closeListeningSockets(int unlink_unix_socket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Reset cpu affinity as soon as new process fork().
|
||||||
|
* For new process will use same cpu core with redis server. */
|
||||||
|
void resetCpuAffinity(const char* name)
|
||||||
|
{
|
||||||
|
int j = 0, s = 0;
|
||||||
|
cput_set_t cpuset_frm, cpuset_to;
|
||||||
|
pthread_t thread;
|
||||||
|
#ifdef __linux__
|
||||||
|
thread = pthread_self();
|
||||||
|
CPU_ZERO(&cpuset_frm);
|
||||||
|
CPU_ZERO(&cpuset_to);
|
||||||
|
|
||||||
|
pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset_frm);
|
||||||
|
for (j = 0; j < CPU_SETSIZE; j++)
|
||||||
|
{
|
||||||
|
if ( CPU_ISSET(j, &cpuset_frm) )
|
||||||
|
continue;
|
||||||
|
CPU_SET(j, &cpuset_to);
|
||||||
|
}
|
||||||
|
s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset_to);
|
||||||
|
if (s != 0)
|
||||||
|
serverLog(LL_WARNING,"set cpu affinity, failed.");
|
||||||
|
if (name!=NULL)
|
||||||
|
{
|
||||||
|
pthread_setname_np(thread, name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int prepareForShutdown(int flags) {
|
int prepareForShutdown(int flags) {
|
||||||
int save = flags & SHUTDOWN_SAVE;
|
int save = flags & SHUTDOWN_SAVE;
|
||||||
int nosave = flags & SHUTDOWN_NOSAVE;
|
int nosave = flags & SHUTDOWN_NOSAVE;
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
@ -1332,6 +1333,8 @@ void populateCommandTable(void);
|
||||||
void resetCommandTableStats(void);
|
void resetCommandTableStats(void);
|
||||||
void adjustOpenFilesLimit(void);
|
void adjustOpenFilesLimit(void);
|
||||||
void closeListeningSockets(int unlink_unix_socket);
|
void closeListeningSockets(int unlink_unix_socket);
|
||||||
|
void resetCpuAffinity(const char* name);
|
||||||
|
|
||||||
void updateCachedTime(void);
|
void updateCachedTime(void);
|
||||||
void resetServerStats(void);
|
void resetServerStats(void);
|
||||||
unsigned int getLRUClock(void);
|
unsigned int getLRUClock(void);
|
||||||
|
|
Loading…
Reference in New Issue