How to determine the number of elements in RemoteChannel?

Hi Community!

The simple Cannel show the current number of elements directly:

B = Channel(2)
put!(B,"one")
put!(B,"two")
B

Channel{Any}(sz_max:2,sz_curr:2)

the sz_curr is current numbers of elements in channel.

In case of RemoteChannel I can’t see something like sz_curr:

jobs = RemoteChannel(()->Channel{Any}(100));
put!(jobs,"one")
put!(jobs,"two")
jobs

RemoteChannel{Channel{Any}}(1, 1, 4)

so it prints only type of RemoteChannel.

How to see current numbers of elements in RemoteChannel?

As I understand it, since RemoteChannel is essentially a reference to a Channel{Any}(1), the number of values it has stored is either 0 or 1. You can distinguish between these two cases using isready.

I try for understand how to view numbers of elements for logging purposes. Anyway, in case of Channel it is really clean. But RemoteChannel is a black box. For example in RemoteChannel{Channel{Any}}(1, 1, 4) the (1, 1, 4) is not informative at all.

Moved it to Parallel/Distributed

Sorry to revive and old thread, but I recently came across the same issue and solved it as follows (Julia 1.10).
From the master process, it is possible to access a RemoteChannel’s underlying Channel via

channel = channel_from_id(remoteref_id(remote_channel)).

Calling Base.n_avail(channel) then returns the number of queued elements. The underlying channel can only be accessed from the master process, so if you want to get the number of elements from a worker process, you need to wrap everything in a remotecall_fetch.

1 Like