# How to determine the number of elements in RemoteChannel?

**URL:** <https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143>\
**Category:** Julia at Scale\
**Created:** [January 27, 2019, 11:11am UTC](https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143 "2019-01-27T11:11:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jamm/32/7118_2.png) [@jamm](https://discourse.julialang.org/u/jamm)\
**Post date:** [January 27, 2019, 11:11am UTC](https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143/1 "2019-01-27T11:11:19Z")

</div>

Hi Community!

The simple Cannel show the current number of elements directly:

```julia
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`:

```julia
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?

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [January 27, 2019, 4:46pm UTC](https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143/2 "2019-01-27T16:46:26Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![jamm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jamm/32/7118_2.png) [@jamm](https://discourse.julialang.org/u/jamm)\
**Post date:** [January 28, 2019, 10:01am UTC](https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143/3 "2019-01-28T10:01:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jamm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jamm/32/7118_2.png) [@jamm](https://discourse.julialang.org/u/jamm)\
**Post date:** [March 20, 2019, 10:34pm UTC](https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143/4 "2019-03-20T22:34:45Z")

</div>

Moved it to [Parallel/Distributed](https://discourse.julialang.org/c/domain/parallel)

---

<div class="post-metadata">

**Author:** ![leapsheep](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@leapsheep](https://discourse.julialang.org/u/leapsheep)\
**Post date:** [February 22, 2024, 12:08pm UTC](https://discourse.julialang.org/t/how-to-determine-the-number-of-elements-in-remotechannel/20143/5 "2024-02-22T12:08:28Z")

</div>

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`.
