eclipse-cyclonedds / eclipse-cyclonedds/cyclonedds-python

Achieving true zero-copy with Iceoryx (Shared Memory)

Open
#294 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
110
Forks
68
Avg merge
1h 8m
Merged PRs (30d)
1

Description

Hi everyone, I've been trying to use this library with CycloneDDS and Iceoryx. I built both libraries from source and can verify everything works from examples & benchmarks.

However, I'm struggling to achieve true zero-copy for large messages (raw images; ~5 MiB/image, 24 Hz). This is my sample IDL:

module TestMessage {
    struct CameraImage {
        unsigned long width;
        unsigned long height;
        sequence<octet> image_data;
    };
};

Given a numpy array, I can use arr.to_bytes() to publish the message. However, it takes ~350 ms to do so:

msg_instance = CameraImage_type(
     width=arr.shape[1],
     height=arr.shape[0],
     image_data=arr.to_bytes()
)
self.writer.write(msg_instance)

Using np.ascontiguousarray() and memoryview, I can get it down to ~0.1 ms:

contiguous_arr = np.ascontiguousarray(image_np)
c_buffer = memoryview(contiguous_arr.data)

msg_instance = CameraImage_type(
    width=contiguous_arr.shape[1],
    height=contiguous_arr.shape[0],
    image_data=c_buffer
)
self.writer.write(msg_instance)

BUT it quickly fails (~30 calls) with this error:

Failed to encode member image_data, value is <memory at 0x72118cf35990>

I was guessing that Python garbage collection is not in tune with CycloneDDS & Iceoryx. So I tried keeping explicit references to the last 1000 references to both contiguous_arr and c_buffer in a collection.deque() - without success.

Is there another way of making this work?

Best
Fabian

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the CameraImage_type construction and writer.write(msg_instance) path, reproducing the memoryview case with the provided IDL and the failure after about 30 calls. Done means large image messages publish reliably without the encoding error, with the zero-copy behavior documented or bounded by the implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.