Skip to content

Optimizing logging calls to reduce requests#

Related error

Experiencing connection interruptions. Will try to reestablish communication with Neptune. Internal exception was: HTTPTooManyRequests

This error occurs when there's a delay between logging data and sending it to the Neptune servers. The error doesn't imply data loss or throttling; it means that you can't watch the training process in real time in the Neptune app.

To avoid sending too many requests to the Neptune server too frequently, you can optimize your logging calls.

Series#

If you're logging a series, you can use the extend() method instead of append().

The below involves ten logging calls:

for value in range(10):
    run["values"].append(value)

The following results in the same metadata structure, but involves a single logging call:

run["values"].extend([value for value in range(10)])

The tradeoff is that in the first case, values are logged almost as soon as they are generated. This is not the case with the latter.

Logging multiple series fields in nested loops#

To optimize batching when creating multiple series fields in a single statement, iterate through the fields in the outer loop and the values in the inner loop:

Doesn't batch well
for i in range(1000):
    for field in range(500):
        run[f"my_metric_{field}"].append(i)
Improves batching
for field in range(500):
    for i in range(1000):
        run[f"my_metric_{field}"].append(i)

Files#

Uploading files one by one with the upload() method results in one File field for each file. Instead, to log files in batch, you can do one of the following:


Getting help