Skip to content

Commit 913f95a

Browse files
committed
cpuhours metric
1 parent cd46486 commit 913f95a

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ To install or update LODA, please follow the [installation instructions](https:/
99
### Features
1010

1111
* Built-in parallel mining command: `loda mine -p` (replaces `mine_parallel.sh` script)
12+
* New metrics on program submissions and CPU hours
1213

1314
### Enhancements
1415

src/api_client.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ bool ApiClient::postProgram(const std::string& path, bool fail_on_error) {
5656
return true;
5757
}
5858

59+
void ApiClient::postCPUHour() {
60+
const std::string url = BASE_URL + "cpuhours";
61+
if (!WebClient::postFile(url, {})) {
62+
Log::get().warn("Error reporting CPU hour");
63+
}
64+
}
65+
5966
bool ApiClient::getProgram(int64_t index, const std::string& path) {
6067
std::remove(path.c_str());
6168
return WebClient::get(BASE_URL + "programs/" + std::to_string(index), path,

src/include/api_client.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class ApiClient {
1212

1313
bool postProgram(const std::string& path, bool fail_on_error = true);
1414

15+
void postCPUHour();
16+
1517
Program getNextProgram();
1618

1719
private:

src/include/miner.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Miner {
4949
std::unique_ptr<Mutator> mutator;
5050
AdaptiveScheduler log_scheduler;
5151
AdaptiveScheduler metrics_scheduler;
52+
AdaptiveScheduler cpuhours_scheduler;
5253
AdaptiveScheduler api_scheduler;
5354
AdaptiveScheduler reload_scheduler;
5455
int64_t num_processed;

src/miner.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ Miner::Miner(const Settings &settings)
2222
mining_mode(Setup::getMiningMode()),
2323
log_scheduler(120), // 2 minutes (magic number)
2424
metrics_scheduler(Metrics::get().publish_interval),
25-
api_scheduler(600), // 10 minutes (magic number)
26-
reload_scheduler(21600), // 6 hours (magic number)
25+
api_scheduler(600), // 10 minutes (magic number)
26+
cpuhours_scheduler(3600), // 1 hour (fixed!!)
27+
reload_scheduler(21600), // 6 hours (magic number)
2728
num_processed(0),
2829
num_new(0),
2930
num_updated(0),
@@ -167,6 +168,12 @@ void Miner::checkRegularTasks() {
167168
num_removed = 0;
168169
}
169170

171+
// regular task: report CPU hours
172+
if (cpuhours_scheduler.isTargetReached()) {
173+
cpuhours_scheduler.reset();
174+
api_client->postCPUHour();
175+
}
176+
170177
// regular task: reload oeis manager and generators
171178
if (reload_scheduler.isTargetReached()) {
172179
reload_scheduler.reset();

src/web_client.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ bool WebClient::postFile(const std::string &url, const std::string &file_path,
6161
if (!auth.empty()) {
6262
cmd += " -u " + auth;
6363
}
64-
cmd += " --data-binary \"@" + file_path + "\" " + url;
64+
if (file_path.empty()) {
65+
cmd += " -X POST";
66+
} else {
67+
cmd += " --data-binary \"@" + file_path + "\"";
68+
}
69+
cmd += " " + url;
6570
break;
6671
}
6772
case WC_WGET: {

0 commit comments

Comments
 (0)