Skip to content

Commit

Permalink
Fix worker test
Browse files Browse the repository at this point in the history
Github actions were running low on memory causing ENOMEM errors
when running the test_work test.

This commit lowers the number of background coroutines in hopes
to alleviate the memory pressure.
  • Loading branch information
tidwall committed May 13, 2024
1 parent d808a81 commit 052e4c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions deps/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include <string.h>
#include <pthread.h>

#ifdef WORKER_STATIC
#define WORKER_API static
#else
#define WORKER_API
#endif

#define WORKER_DEF_TIMEOUT INT64_C(1000000000) // one second
#define WORKER_DEF_MAX_THREADS 2
#define WORKER_DEF_MAX_THREAD_ENTRIES 32
Expand Down Expand Up @@ -46,6 +52,7 @@ struct worker {
void (*free)(void*);
};

WORKER_API
void worker_free(struct worker *worker) {
if (worker) {
if (worker->threads) {
Expand All @@ -70,6 +77,7 @@ void worker_free(struct worker *worker) {
}
}

WORKER_API
struct worker *worker_new(struct worker_opts *opts) {
// Load options
int nthreads = opts ? opts->max_threads : 0;
Expand Down Expand Up @@ -164,6 +172,7 @@ static void *worker_entry(void *arg) {
/// @param udata any user data
/// @return true for success or false if no worker is available.
/// @return false for invalid arguments. Worker and work must no be null.
WORKER_API
bool worker_submit(struct worker *worker, int64_t pin, void(*work)(void *udata),
void *udata)
{
Expand Down
19 changes: 18 additions & 1 deletion neco.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ NECO_NOWRITEWORKERS // Disable all write workers
#undef NECO_BURST
#define NECO_BURST 1
#endif
#if NECO_MAXWORKERS > 8
#undef NECO_MAXWORKERS
#define NECO_MAXWORKERS 8
#endif
#if NECO_MAXRINGSIZE > 4
#undef NECO_MAXRINGSIZE
#define NECO_MAXRINGSIZE 4
#endif
#endif


// The following is only needed when LLCO_NOASM or LLCO_STACKJMP is defined.
// This same block is duplicated in the llco.c block below.
Expand Down Expand Up @@ -137,6 +144,7 @@ NECO_NOWRITEWORKERS // Disable all write workers

#define SCO_STATIC
#define STACK_STATIC
#define WORKER_STATIC

#if defined(__GNUC__)
#pragma GCC diagnostic push
Expand Down Expand Up @@ -2623,6 +2631,12 @@ void *stack_addr(struct stack *stack) {
#include <string.h>
#include <pthread.h>

#ifdef WORKER_STATIC
#define WORKER_API static
#else
#define WORKER_API
#endif

#define WORKER_DEF_TIMEOUT INT64_C(1000000000) // one second
#define WORKER_DEF_MAX_THREADS 2
#define WORKER_DEF_MAX_THREAD_ENTRIES 32
Expand Down Expand Up @@ -2657,6 +2671,7 @@ struct worker {
void (*free)(void*);
};

WORKER_API
void worker_free(struct worker *worker) {
if (worker) {
if (worker->threads) {
Expand All @@ -2681,6 +2696,7 @@ void worker_free(struct worker *worker) {
}
}

WORKER_API
struct worker *worker_new(struct worker_opts *opts) {
// Load options
int nthreads = opts ? opts->max_threads : 0;
Expand Down Expand Up @@ -2775,6 +2791,7 @@ static void *worker_entry(void *arg) {
/// @param udata any user data
/// @return true for success or false if no worker is available.
/// @return false for invalid arguments. Worker and work must no be null.
WORKER_API
bool worker_submit(struct worker *worker, int64_t pin, void(*work)(void *udata),
void *udata)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void co_work_runner(int argc, void *argv[]) {

void co_work(int argc, void *argv[]) {
(void)argc; (void)argv;
for (int i = 0; i < 10000; i++) {
for (int i = 0; i < 100; i++) {
expect(neco_start(co_work_runner, 1, &i), NECO_OK);
}
}
Expand Down

0 comments on commit 052e4c5

Please sign in to comment.