Skip to content

Commit

Permalink
Merge branch 'kris-lab-priority-status' into upstream_master
Browse files Browse the repository at this point in the history
  • Loading branch information
SpamapS committed Dec 14, 2016
2 parents e586567 + d989576 commit 33fccc5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
20 changes: 20 additions & 0 deletions PROTOCOL
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,26 @@ status
Arguments:
- None.

prioritystatus

This sends back a list of all registered functions. Next to each
function is the number of queued jobs that are not running, broken down
by priority, and the number of capable workers. The columns are tab
separated, and the list is terminated with a line containing
a single '.' (period). The format is:

FUNCTION\tHIGH-QUEUED\tNORMAL-QUEUED\tLOW-QUEUED\tAVAILABLE_WORKERS

Columns:
- Function name.
- Number of queued high priority jobs.
- Number of queued normal priority jobs.
- Number of queued low priority jobs.
- Available workers registered for this function.

Arguments:
- None.

maxqueue

This sets the maximum queue size for a function. If no size is
Expand Down
7 changes: 7 additions & 0 deletions bin/gearadmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ int main(int args, char *argv[])
("show-jobs", "Show all jobs on the server.")
("getpid", "Get Process ID for the server.")
("status", "Status for the server.")
("priority-status", "Queued jobs status by priority.")
("workers", "Workers for the server.")
("ssl,S", "Enable SSL connections.")
;
Expand Down Expand Up @@ -183,6 +184,7 @@ int main(int args, char *argv[])
vm.count("show-jobs") == 0 and
vm.count("getpid") == 0 and
vm.count("status") == 0 and
vm.count("priority-status") == 0 and
vm.count("workers") == 0)
{
std::cout << "No option execution operation given." << std::endl << std::endl;
Expand All @@ -196,6 +198,11 @@ int main(int args, char *argv[])
instance.push(new util::Operation(util_literal_param("status\r\n")));
}

if (vm.count("priority-status"))
{
instance.push(new util::Operation(util_literal_param("prioritystatus\r\n")));
}

if (vm.count("workers"))
{
instance.push(new util::Operation(util_literal_param("workers\r\n")));
Expand Down
34 changes: 33 additions & 1 deletion libgearman-server/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ gearmand_error_t server_run_text(gearman_server_con_st *server_con,

data.vec_append_printf(".\n");
}
else if (strcasecmp("prioritystatus", (char *)(packet->arg[0])) == 0)
{
uint32_t job_queued[GEARMAN_JOB_PRIORITY_MAX];

for (uint32_t function_key= 0;
function_key < GEARMAND_DEFAULT_HASH_SIZE;
function_key++)
{
for (gearman_server_function_st *function= Server->function_hash[function_key];
function != NULL;
function= function->next)
{
for (size_t priority = 0; priority < GEARMAN_JOB_PRIORITY_MAX; priority++)
{
job_queued[priority] = 0;
for (gearman_server_job_st *server_job= function->job_list[priority];
server_job != NULL;
server_job= server_job->next)
{
job_queued[priority]++;
}
}

data.vec_append_printf("%.*s\t%u\t%u\t%u\t%u\n",
int(function->function_name_size), function->function_name,
job_queued[GEARMAN_JOB_PRIORITY_HIGH],
job_queued[GEARMAN_JOB_PRIORITY_NORMAL],
job_queued[GEARMAN_JOB_PRIORITY_LOW],
function->worker_count);
}
}
data.vec_append_printf(".\n");
}
else if (strcasecmp("status", (char *)(packet->arg[0])) == 0)
{
for (uint32_t function_key= 0;
Expand All @@ -135,7 +168,6 @@ gearmand_error_t server_run_text(gearman_server_con_st *server_con,
function->job_running, function->worker_count);
}
}

data.vec_append_printf(".\n");
}
else if (packet->argc >= 3
Expand Down
13 changes: 13 additions & 0 deletions tests/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ static test_return_t gearadmin_status_with_jobs_TEST(void* object)
return TEST_SUCCESS;
}

static test_return_t gearadmin_priority_status_TEST(void* object)
{
cli::Context *context= (cli::Context*)object;

char buffer[1024];
snprintf(buffer, sizeof(buffer), "--port=%d", int(context->port()));
const char *args[]= { buffer, "--priority-status", 0 };

ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args, true));
return TEST_SUCCESS;
}

static test_return_t gearadmin_show_unique_jobs_TEST(void* object)
{
cli::Context *context= (cli::Context*)object;
Expand Down Expand Up @@ -430,6 +442,7 @@ test_st gearadmin_tests[] ={
{"--show-jobs", 0, gearadmin_show_jobs_TEST},
{"--show-unique-jobs", 0, gearadmin_show_unique_jobs_TEST},
{"--status", 0, gearadmin_status_TEST},
{"--priority-status", 0, gearadmin_priority_status_TEST},
{"gearman_client_do_background(100) --status", 0, gearadmin_status_with_jobs_TEST},
{"--getpid", 0, gearadmin_getpid_test},
{"--workers", 0, gearadmin_workers_test},
Expand Down

3 comments on commit 33fccc5

@octavn
Copy link

@octavn octavn commented on 33fccc5 May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't get this functionality to work on 1.1.19.1

We've pushed 100 high, 50 normal and 10 low jobs on thefoo function with 0 workers and this is the output we're getting:

gearadmin --priority-status
bar 0 0 0 0
convert 0 0 0 25
foo 1 1 2 0

Telnet prioritystatus output is the same.

So only 1 high, 1 medium and 2 low instead of 100 50 10! gearadmin --show-unique-jobs shows all 160 unique ids.

@esabol
Copy link
Member

@esabol esabol commented on 33fccc5 May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open an issue for tracking purposes.

@octavn
Copy link

@octavn octavn commented on 33fccc5 May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open an issue for tracking purposes.

done, opened #337

Please sign in to comment.