Skip to content

Commit

Permalink
Tweak listener yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 4, 2024
1 parent 6c33ddd commit f8936a7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ A simple, light-weight C/C++ Redis client.

__RedisX__ is a light-weight [Redis](https://redis.io) client for C/C++. As such, it should also work with Redis forks
/ clones like [Dragonfly](https://dragonfly.io) or [Valkey](https://valkey.io). It supports both interactive and
pipelined Redis queries, managing and processing subscriptions. It also supports atomic execution blocks and LUA
scripts loading. It can be used with one or more distinct Redis servers simultaneously.
pipelined Redis queries, managing and processing subscriptions, atomic execution blocks, and LUA scripts loading. It
can be used with multiple Redis servers simultaneously also.

While there are other C/C++ Redis clients available, this one is C90 compatible, and hence can be used on older
platforms also. It is also small and fast, but still capable and versatile.
Expand All @@ -49,12 +49,6 @@ the pace new commands are being introduced all the time), it provides a basic fr
asynchronous queries, with some higher-level functions for managing key/value storage types (including hash tables),
and PUB/SUB. Future releases may add further higher-level functionality based on demand for such features.

The library maintains up to three separate connections (channels) for each separate Redis server instance used: (1) an
interactive client for sequential round-trip transactions, (2) a pipeline client for bulk queries and asynchronous
background processing, and (3) a subscription client for PUB/SUB requests and notifications. The interactive client is
always connected, the pipeline client is connected only if explicitly requested at the time of establishing the server
connection, while the subscription client is connected only as needed.

The __RedisX__ library was created, and is maintained, by Attila Kovács at the Center for Astrophysics \| Harvard
& Smithsonian, and it is available through the [Smithsonian/redisx](https://github.com/Smithsonian/redisx)
repository on GitHub.
Expand Down Expand Up @@ -97,7 +91,7 @@ prior to invoking `make`. The following build variables can be configured:

- `CFLAGS`: Flags to pass onto the C compiler (default: `-Os -Wall`). Note, `-Iinclude` will be added automatically.

- `LDFLAGS`: Linker flags (default is `-lm`).
- `LDFLAGS`: Linker flags (default is `-lm`). Note, `-lxchange` will be added automatically.

- `CHECKEXTRA`: Extra options to pass to `cppcheck` for the `make check` target

Expand All @@ -117,6 +111,12 @@ desired `make` target(s). (You can use `make help` to get a summary of the avail
- [Disconnecting](#disconnecting)
- [Connection hooks](#connection-hooks)

The library maintains up to three separate connections (channels) for each separate Redis server instance used: (1) an
interactive client for sequential round-trip transactions, (2) a pipeline client for bulk queries and asynchronous
background processing, and (3) a subscription client for PUB/SUB requests and notifications. The interactive client is
always connected, the pipeline client is connected only if explicitly requested at the time of establishing the server
connection, while the subscription client is connected only as needed.

<a name="initializing"></a>
### Initializing

Expand Down
9 changes: 6 additions & 3 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ CFLAGS ?= -Os -Wall
# Add include/ directory
CFLAGS += -I$(INC)

# Extra warnings (not supported on all compilers)
#CFLAGS += -Wextra

# Link against math libs (for e.g. isnan())
LDFLAGS ?= -lm

# Compile and link against a specific xchange library (if defined)
ifdef XCHANGE
CFLAGS += -I$(XCHANGE)/include
LDFLAGS += -L$(XCHANGE)/lib -lxchange
LDFLAGS = -L$(XCHANGE)/lib
LD_LIBRARY_PATH = $(XCHANGE)/lib:$(LD_LIBRARY_PATH)
endif

# Extra warnings (not supported on all compilers)
#CFLAGS += -Wextra
# Always link against the xchange lib.
LDFLAGS += -lxchange

# cppcheck options for 'check' target
CHECKOPTS ?= --enable=performance,warning,portability,style --language=c \
Expand Down
4 changes: 2 additions & 2 deletions include/redisx.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#ifndef REDISX_LISTENER_REL_PRIORITY
/// [0.0:1.0] Listener priority as fraction of available range
/// You may want to set it quite high to ensure that the receive buffer is promptly cleared.
# define REDISX_LISTENER_REL_PRIORITY (0.9)
# define REDISX_LISTENER_REL_PRIORITY (0.5)
#endif

// Various exposed constants ----------------------------------------------------->
Expand Down Expand Up @@ -199,7 +199,7 @@ typedef struct Redis {
* be binary a '\0' termination should no be assumed. Instead, the
* length of the message is specified explicitly.
*/
typedef void (*RedisSubscriberCall)(const char *pattern, const char *channel, const char *msg, int length);
typedef void (*RedisSubscriberCall)(const char *pattern, const char *channel, const char *msg, long length);


/**
Expand Down
2 changes: 1 addition & 1 deletion resources/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta charset="utf-8"/>
<meta name="description" content="A light-weight Redis client library for C/C++"/>
<meta name="keywords" content="redis client, C, C++, library"/>
<meta name="keywords" content="Redis client library, C, C++, C90, software library, open source"/>
<meta name="author" content="Attila Kovacs"/>
<meta name="copyright" content="(C)2024 Attila Kovacs" />
<meta name="robots" content="index,follow"/>
Expand Down
9 changes: 0 additions & 9 deletions src/redisx-sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,6 @@ void redisxEndSubscription(Redis *redis) {
}

static void rNotifyConsumers(Redis *redis, char *pattern, char *channel, char *msg, int length) {
#if REDISX_LISTENER_YIELD_COUNT > 0
static int count;
#endif

MessageConsumer *c;
RedisPrivate *p;
RedisSubscriberCall *f = NULL;
Expand Down Expand Up @@ -519,11 +515,6 @@ static void rNotifyConsumers(Redis *redis, char *pattern, char *channel, char *m
for(i=0; i<n; i++) f[i](pattern, channel, msg, length);
free(f);
}

#if REDISX_LISTENER_YIELD_COUNT > 0
// Allow the waiting processes to take control...
if(++count % REDISX_LISTENER_YIELD_COUNT == 0) sched_yield();
#endif
}

/// \cond PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/redisx.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define XPRIO_MAX (sched_get_priority_max(SCHED_RR))
#define XPRIO_RANGE (XPRIO_MAX - XPRIO_MIN)

#define REDISX_LISTENER_PRIORITY (XPRIO_MIN + (int) (REDISX_LISTENER_REL_PRIORITY * XPRIO_RANGE))
#define REDISX_LISTENER_PRIORITY (XPRIO_MIN + (int) (REDISX_LISTENER_REL_PRIORITY * XPRIO_RANGE))

typedef struct ServerLink {
Redis *redis;
Expand Down

0 comments on commit f8936a7

Please sign in to comment.