basler / pypylon

The official python wrapper for the pylon Camera Software Suite
http://www.baslerweb.com
BSD 3-Clause "New" or "Revised" License
575 stars 208 forks source link

BUG: Memory leakage in pypylon 3.0.1? #762

Closed Jannick-v closed 4 months ago

Jannick-v commented 4 months ago

Describe the issue:

I am currently facing several issues in one of my projects. A potential memory leak is one of them. In an attempt to isolate the problem, I have tried to extract a MWE from the application code.

The real application runs in a k3s pod on a Jetson device. However, for debugging purposes I am currently moving from bare metal (conda env) --> docker env--> k3s env. When running in a docker container, the container crashes with an OOM.

After closer inspection, I have noticed a similar memory increase when running on bare metal too. But since the system has 32 GB of memory, the build-up did go unnoticed first.

The following docker run flags are used:

I've tested this with a few docker base images, always with the same result:

When running inside the docker container, I can see a stead memory build-up happening using docker stats, until the docker container eventually crashes due to an OOM after a few minutes

The camera (a ral4096-24gm Linescan camera) is currently producing 800x420 mono images at a rate of ~ 4 FPS. (line rate ~3003.0 Hz)

Reproduce the code example:

import logging
import shutil
from pathlib import Path
import os
import time
from pypylon import pylon, genicam
from typing import List, Union, Optional
import gc
logger = logging.getLogger(__name__)

ROOT = Path(__file__).parent
IMG_DIR = Path(os.environ.get("IMG_DIR", ROOT / "images"))

PFS_FILE = ROOT / "camera.pfs"
SERIAL_NUMER = "24713383"
ZERO_COPY = True
CAMERA_IP = "10.102.3.53"
TIMEOUT = 5000

tl_factory = pylon.TlFactory.GetInstance()

def connect_cam_on_serial(serial_number: str) -> pylon.InstantCamera:
    cam = None
    for dev_info in tl_factory.EnumerateDevices():
        if dev_info.GetSerialNumber() == serial_number:
            cam = pylon.InstantCamera(tl_factory.CreateDevice(dev_info))
            break
    if cam is None:
        raise IOError(f"no camera with serial {serial_number} in {[d.GetFriendlyName() for d in tl_factory.EnumerateDevices()]}")
    else:
        cam.Open()
        logger.info(f"camera opened with {serial_number=}")
        return cam        

def connect_cam_on_ip(ip:str) -> pylon.InstantCamera:
    device_info = pylon.DeviceInfo()
    device_info = device_info.SetAddress(AddressValue=ip)
    device_info.SetDeviceClass("BaslerGigE")
    cam = pylon.InstantCamera(tl_factory.CreateFirstDevice(device_info))
    cam.Open()
    logger.info(f"camera opened with {ip=}")
    return cam

def print_device_info(cam: pylon.InstantCamera):
    device_node_map = cam.GetNodeMap()
    device_info_list = [
        ("Device Model Name", device_node_map.GetNode("DeviceModelName").GetValue()),
        ("Device Manufacturer Info", device_node_map.GetNode("DeviceManufacturerInfo").GetValue()),
        ("Device Version", device_node_map.GetNode("DeviceVersion").GetValue()),
        ("Device Firmware Version", device_node_map.GetNode("DeviceFirmwareVersion").GetValue()),
        ("Device Serial Number", device_node_map.GetNode("DeviceSerialNumber").GetValue()),
        ("Device ID", device_node_map.GetNode("DeviceID").GetValue()),
        ("Device User ID", device_node_map.GetNode("DeviceUserID").GetValue())
    ]

    logger.info("Device Information:")
    for info_name, info_value in device_info_list:
        logger.info(f"{info_name};  {info_value}")

def load_camera_config(cam: pylon.InstantCamera, configfile: Union[Path,str]):
    if cam.IsOpen():
        pylon.FeaturePersistence.Load(str(configfile), cam.GetNodeMap(), True)

def set_buffer_sizes(cam: pylon.InstantCamera):
    if not cam.IsOpen():
        logger.info("Opening camera")
        cam.Open()

    old_val = cam.MaxNumBuffer()
    cam.MaxNumBuffer = 10000
    new_val = cam.MaxNumBuffer()
    logger.info(f"MaxNumBuffer size set successfully. {old_val} --> {new_val}")

    old_val = cam.OutputQueueSize()
    cam.OutputQueueSize.Value = 10000
    new_val = cam.OutputQueueSize()
    logger.info(f"OutputQueueSize set successfully. {old_val} --> {new_val}")

    old_val = cam.MaxNumQueuedBuffer()
    cam.MaxNumQueuedBuffer.Value = 200
    new_val = cam.MaxNumQueuedBuffer()
    logger.info(f"MaxNumQueuedBuffer set successfully. {old_val} --> {new_val}")

def setup_img_dir() -> None:
    try:
        shutil.rmtree(IMG_DIR)
    except FileNotFoundError:
        pass
    IMG_DIR.mkdir(parents=True)

if __name__ == "__main__":
    import sys, pypylon.pylon, platform

    logging.basicConfig(level=logging.DEBUG)
    setup_img_dir()

    print(f'python: {sys.version}')
    print(f'platform: {sys.platform}/{platform.machine()}/{platform.release()}')
    print(f'pypylon: {pypylon.pylon.__version__} / {".".join([str(i) for i in pypylon.pylon.GetPylonVersion()])}')

    devices = tl_factory.EnumerateDevices()
    logger.info(f"Devices: {[d.GetFriendlyName() for d in devices]}")

    cam = connect_cam_on_serial(SERIAL_NUMER)

    logger.info(f"connected to {cam.GetDeviceInfo().GetSerialNumber()}")

    # cam = connect_cam_on_ip(CAMERA_IP)
    load_camera_config(cam, configfile=PFS_FILE)
    set_buffer_sizes(cam)

    cam.StartGrabbing(pylon.GrabStrategy_OneByOne)

    start = time.time()

    frame_count = 0
    grab_failed_count = 0
    invalid_result_count = 0
    timeout_count = 0 

    logger.info("start")

    # while cam.IsGrabbing():
    while True:

        try:
            with cam.RetrieveResult(TIMEOUT, pylon.TimeoutHandling_ThrowException) as result:
                frame_count += 1
                logger.info(f"Buffer info: {cam.NumQueuedBuffers()=}, {cam.NumReadyBuffers()=}, {cam.NumEmptyBuffers()=}")
                if not result.GrabSucceeded():
                    grab_failed_count += 1
                    raise pylon.RuntimeException(f"Grab ({grab_failed_count}/{frame_count})did not succeed - {result.GetErrorCode()}: {result.GetErrorDescription()}")
                if not result.IsValid():
                    invalid_result_count += 1
                    raise pylon.RuntimeException("invalid result!")

                if not ZERO_COPY:
                        # img = pylon.PylonImage()
                        imgdata = result.GetArray()
                        # in the real application, we would push the imgdata on a queue here

                else:
                    with result.GetArrayZeroCopy() as res:
                        imgdata = res.copy()
                        # in the real application, we would push the imgdata on a queue here

                # get_all_chunk_info(chunks=camera_chunks)

        except pylon.TimeoutException:
            timeout_count += 1
            logger.error("grab timeout!")

        except (SystemError, KeyboardInterrupt):
            break
        except:
            logger.exception("something")

        finally:
            logger.info(f"stats: {frame_count=}, {grab_failed_count=}, {invalid_result_count=}, {timeout_count=}")
            result.Release()

    cam.StopGrabbing()
    cam.Close()
    logger.info("camera closed")

### Error message:

```shell
no real error message, but a steady increase of memory usage reported by `docker stats` until the running container goes OOM.

Is your camera operational in Basler pylon viewer on your platform

Yes

Hardware setup & camera model(s) used

compute device:

camera:

Runtime information:

python: 3.8.16 (default, May 23 2023, 09:52:14) 
[GCC 10.2.1 20210110]
platform: linux/aarch64/5.10.104-tegra
pypylon: 3.0.1 / 7.4.0.38864
$ docker info
Client: Docker Engine - Community
 Version:    26.1.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 50
  Running: 0
  Paused: 0
  Stopped: 50
 Images: 23
 Server Version: 26.1.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.10.104-tegra
 Operating System: Ubuntu 20.04.6 LTS
 OSType: linux
 Architecture: aarch64
 CPUs: 8
 Total Memory: 29.87GiB
 Name: ubuntu
 ID: a3c92f65-f37a-46c4-a94a-d2ab0b1c0e1f
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

pfs file:

# {05D8C294-F295-4dfb-9D01-096BD04049F4}
# GenApi persistence file (version 3.1.0)
# Device = Basler::GigECamera -- Basler generic GigEVision camera interface -- Device version = 3.2.0 -- Product GUID = 1F3C6A72-7842-4edd-9130-E2E90A2058BA -- Product version GUID = F02956CC-AEBB-4EA0-ABF5-003BDC0210C6
GainAuto    Off
GainSelector    All
GainRaw 1000
GainSelector    AnalogAll
GainRaw 4
GainSelector    DigitalAll
GainRaw 1000
GainSelector    DigitalAll
BlackLevelSelector  All
BlackLevelRaw   0
BlackLevelSelector  All
GammaEnable 0
GammaSelector   User
Gamma   1
PixelFormat Mono8
ReverseX    0
TestImageSelector   Off
Width   420
Height  800
OffsetX 645
OffsetY 0
CenterX 0
BinningModeHorizontal   Summing
BinningHorizontal   1
AcquisitionFrameCount   1
TriggerSelector AcquisitionStart
TriggerMode Off
TriggerSelector FrameStart
TriggerMode Off
TriggerSelector LineStart
TriggerMode On
TriggerSelector FrameStart
TriggerSelector AcquisitionStart
TriggerSource   Line3
TriggerSelector FrameStart
TriggerSource   Line3
TriggerSelector LineStart
TriggerSource   Line1
TriggerSelector FrameStart
TriggerSelector AcquisitionStart
TriggerActivation   RisingEdge
TriggerSelector FrameStart
TriggerActivation   RisingEdge
TriggerSelector LineStart
TriggerActivation   RisingEdge
TriggerSelector FrameStart
TriggerSelector AcquisitionStart
TriggerDelaySource  LineTrigger
TriggerSelector FrameStart
TriggerDelaySource  LineTrigger
TriggerSelector FrameStart
TriggerSelector AcquisitionStart
TriggerDelayLineTriggerCount    0
TriggerSelector FrameStart
TriggerDelayLineTriggerCount    4825
TriggerSelector FrameStart
ExposureMode    Timed
ExposureAuto    Off
ExposureTimeRaw 3000
AcquisitionLineRateAbs  30030
FrameTimeoutEnable  0
LineSelector    Line1
LineMode    Input
LineSelector    Line2
LineMode    Input
LineSelector    Line3
LineMode    Input
LineSelector    Out1
LineMode    Output
LineSelector    Out2
LineMode    Output
LineSelector    Line1
LineSelector    Line1
LineFormat  RS422
LineSelector    Line2
LineFormat  RS422
LineSelector    Line3
LineFormat  RS422
LineSelector    Out1
LineFormat  RS422
LineSelector    Out2
LineFormat  RS422
LineSelector    Line1
LineSelector    Out1
LineSource  FrameTriggerWait
LineSelector    Out2
LineSource  LineTriggerWait
LineSelector    Line1
LineSelector    Line1
LineInverter    0
LineSelector    Line2
LineInverter    0
LineSelector    Line3
LineInverter    0
LineSelector    Out1
LineInverter    0
LineSelector    Out2
LineInverter    1
LineSelector    Line1
LineSelector    Line1
LineTermination 0
LineSelector    Line2
LineTermination 0
LineSelector    Line3
LineTermination 0
LineSelector    Line1
LineSelector    Line1
LineDebouncerTimeRaw    1000
LineSelector    Line2
LineDebouncerTimeRaw    1000
LineSelector    Line3
LineDebouncerTimeRaw    1000
LineSelector    Line1
LineSelector    Out1
MinOutPulseWidthRaw 100000
LineSelector    Out2
MinOutPulseWidthRaw 100000
LineSelector    Line1
UserOutputValueAll  0
ShaftEncoderModuleLineSelector  PhaseA
ShaftEncoderModuleLineSource    Line1
ShaftEncoderModuleLineSelector  PhaseB
ShaftEncoderModuleLineSource    Line2
ShaftEncoderModuleLineSelector  PhaseA
ShaftEncoderModuleMode  AnyDirection
ShaftEncoderModuleCounterMode   FollowDirection
ShaftEncoderModuleCounterMax    10000
ShaftEncoderModuleReverseCounterMax 0
FrequencyConverterInputSource   Line1
FrequencyConverterSignalAlignment   RisingEdge
FrequencyConverterPreDivider    1
FrequencyConverterMultiplier    1
FrequencyConverterPostDivider   1
CounterSelector Counter2
CounterEventSource  FrameStart
CounterSelector Counter3
CounterEventSource  LineTrigger
CounterSelector Counter2
CounterSelector Counter2
CounterResetSource  Off
CounterSelector Counter3
CounterResetSource  Off
CounterSelector Counter2
LUTSelector Luminance
LUTEnable   0
LUTSelector Luminance
LUTSelector Luminance
LUTValueAll 0x00000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000580000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000006800000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000880000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000009800000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a800000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000b800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000d800000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000e800000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000000f80000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010800000000000000000000000000000000000000000000000000000000000001100000000000000000000000000000000000000000000000000000000000000118000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001280000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000013800000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000148000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000001580000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000016800000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000178000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001880000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000019800000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001a800000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b800000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c800000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000001d800000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000001e800000000000000000000000000000000000000000000000000000000000001f000000000000000000000000000000000000000000000000000000000000001f80000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020800000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000218000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002280000000000000000000000000000000000000000000000000000000000000230000000000000000000000000000000000000000000000000000000000000023800000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000248000000000000000000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000000000000000002580000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000026800000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000278000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002880000000000000000000000000000000000000000000000000000000000000290000000000000000000000000000000000000000000000000000000000000029800000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002a800000000000000000000000000000000000000000000000000000000000002b000000000000000000000000000000000000000000000000000000000000002b800000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002c800000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000002d800000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000002e800000000000000000000000000000000000000000000000000000000000002f000000000000000000000000000000000000000000000000000000000000002f80000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000030800000000000000000000000000000000000000000000000000000000000003100000000000000000000000000000000000000000000000000000000000000318000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000003280000000000000000000000000000000000000000000000000000000000000330000000000000000000000000000000000000000000000000000000000000033800000000000000000000000000000000000000000000000000000000000003400000000000000000000000000000000000000000000000000000000000000348000000000000000000000000000000000000000000000000000000000000035000000000000000000000000000000000000000000000000000000000000003580000000000000000000000000000000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000000000036800000000000000000000000000000000000000000000000000000000000003700000000000000000000000000000000000000000000000000000000000000378000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003880000000000000000000000000000000000000000000000000000000000000390000000000000000000000000000000000000000000000000000000000000039800000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000003a800000000000000000000000000000000000000000000000000000000000003b000000000000000000000000000000000000000000000000000000000000003b800000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000003c800000000000000000000000000000000000000000000000000000000000003d000000000000000000000000000000000000000000000000000000000000003d800000000000000000000000000000000000000000000000000000000000003e000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000003f000000000000000000000000000000000000000000000000000000000000003f80000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040800000000000000000000000000000000000000000000000000000000000004100000000000000000000000000000000000000000000000000000000000000418000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000004280000000000000000000000000000000000000000000000000000000000000430000000000000000000000000000000000000000000000000000000000000043800000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000448000000000000000000000000000000000000000000000000000000000000045000000000000000000000000000000000000000000000000000000000000004580000000000000000000000000000000000000000000000000000000000000460000000000000000000000000000000000000000000000000000000000000046800000000000000000000000000000000000000000000000000000000000004700000000000000000000000000000000000000000000000000000000000000478000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000004880000000000000000000000000000000000000000000000000000000000000490000000000000000000000000000000000000000000000000000000000000049800000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000004a800000000000000000000000000000000000000000000000000000000000004b000000000000000000000000000000000000000000000000000000000000004b800000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000004c800000000000000000000000000000000000000000000000000000000000004d000000000000000000000000000000000000000000000000000000000000004d800000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000004e800000000000000000000000000000000000000000000000000000000000004f000000000000000000000000000000000000000000000000000000000000004f80000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000050800000000000000000000000000000000000000000000000000000000000005100000000000000000000000000000000000000000000000000000000000000518000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000005280000000000000000000000000000000000000000000000000000000000000530000000000000000000000000000000000000000000000000000000000000053800000000000000000000000000000000000000000000000000000000000005400000000000000000000000000000000000000000000000000000000000000548000000000000000000000000000000000000000000000000000000000000055000000000000000000000000000000000000000000000000000000000000005580000000000000000000000000000000000000000000000000000000000000560000000000000000000000000000000000000000000000000000000000000056800000000000000000000000000000000000000000000000000000000000005700000000000000000000000000000000000000000000000000000000000000578000000000000000000000000000000000000000000000000000000000000058000000000000000000000000000000000000000000000000000000000000005880000000000000000000000000000000000000000000000000000000000000590000000000000000000000000000000000000000000000000000000000000059800000000000000000000000000000000000000000000000000000000000005a000000000000000000000000000000000000000000000000000000000000005a800000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000005b800000000000000000000000000000000000000000000000000000000000005c000000000000000000000000000000000000000000000000000000000000005c800000000000000000000000000000000000000000000000000000000000005d000000000000000000000000000000000000000000000000000000000000005d800000000000000000000000000000000000000000000000000000000000005e000000000000000000000000000000000000000000000000000000000000005e800000000000000000000000000000000000000000000000000000000000005f000000000000000000000000000000000000000000000000000000000000005f80000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060800000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000618000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000006280000000000000000000000000000000000000000000000000000000000000630000000000000000000000000000000000000000000000000000000000000063800000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000648000000000000000000000000000000000000000000000000000000000000065000000000000000000000000000000000000000000000000000000000000006580000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000066800000000000000000000000000000000000000000000000000000000000006700000000000000000000000000000000000000000000000000000000000000678000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000006880000000000000000000000000000000000000000000000000000000000000690000000000000000000000000000000000000000000000000000000000000069800000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000006a800000000000000000000000000000000000000000000000000000000000006b000000000000000000000000000000000000000000000000000000000000006b800000000000000000000000000000000000000000000000000000000000006c000000000000000000000000000000000000000000000000000000000000006c800000000000000000000000000000000000000000000000000000000000006d000000000000000000000000000000000000000000000000000000000000006d800000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000006e800000000000000000000000000000000000000000000000000000000000006f000000000000000000000000000000000000000000000000000000000000006f80000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000070800000000000000000000000000000000000000000000000000000000000007100000000000000000000000000000000000000000000000000000000000000718000000000000000000000000000000000000000000000000000000000000072000000000000000000000000000000000000000000000000000000000000007280000000000000000000000000000000000000000000000000000000000000730000000000000000000000000000000000000000000000000000000000000073800000000000000000000000000000000000000000000000000000000000007400000000000000000000000000000000000000000000000000000000000000748000000000000000000000000000000000000000000000000000000000000075000000000000000000000000000000000000000000000000000000000000007580000000000000000000000000000000000000000000000000000000000000760000000000000000000000000000000000000000000000000000000000000076800000000000000000000000000000000000000000000000000000000000007700000000000000000000000000000000000000000000000000000000000000778000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000007880000000000000000000000000000000000000000000000000000000000000790000000000000000000000000000000000000000000000000000000000000079800000000000000000000000000000000000000000000000000000000000007a000000000000000000000000000000000000000000000000000000000000007a800000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000007b800000000000000000000000000000000000000000000000000000000000007c000000000000000000000000000000000000000000000000000000000000007c800000000000000000000000000000000000000000000000000000000000007d000000000000000000000000000000000000000000000000000000000000007d800000000000000000000000000000000000000000000000000000000000007e000000000000000000000000000000000000000000000000000000000000007e800000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000007f80000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000080800000000000000000000000000000000000000000000000000000000000008100000000000000000000000000000000000000000000000000000000000000818000000000000000000000000000000000000000000000000000000000000082000000000000000000000000000000000000000000000000000000000000008280000000000000000000000000000000000000000000000000000000000000830000000000000000000000000000000000000000000000000000000000000083800000000000000000000000000000000000000000000000000000000000008400000000000000000000000000000000000000000000000000000000000000848000000000000000000000000000000000000000000000000000000000000085000000000000000000000000000000000000000000000000000000000000008580000000000000000000000000000000000000000000000000000000000000860000000000000000000000000000000000000000000000000000000000000086800000000000000000000000000000000000000000000000000000000000008700000000000000000000000000000000000000000000000000000000000000878000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000000000000000000000000000000000008880000000000000000000000000000000000000000000000000000000000000890000000000000000000000000000000000000000000000000000000000000089800000000000000000000000000000000000000000000000000000000000008a000000000000000000000000000000000000000000000000000000000000008a800000000000000000000000000000000000000000000000000000000000008b000000000000000000000000000000000000000000000000000000000000008b800000000000000000000000000000000000000000000000000000000000008c000000000000000000000000000000000000000000000000000000000000008c800000000000000000000000000000000000000000000000000000000000008d000000000000000000000000000000000000000000000000000000000000008d800000000000000000000000000000000000000000000000000000000000008e000000000000000000000000000000000000000000000000000000000000008e800000000000000000000000000000000000000000000000000000000000008f000000000000000000000000000000000000000000000000000000000000008f80000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000090800000000000000000000000000000000000000000000000000000000000009100000000000000000000000000000000000000000000000000000000000000918000000000000000000000000000000000000000000000000000000000000092000000000000000000000000000000000000000000000000000000000000009280000000000000000000000000000000000000000000000000000000000000930000000000000000000000000000000000000000000000000000000000000093800000000000000000000000000000000000000000000000000000000000009400000000000000000000000000000000000000000000000000000000000000948000000000000000000000000000000000000000000000000000000000000095000000000000000000000000000000000000000000000000000000000000009580000000000000000000000000000000000000000000000000000000000000960000000000000000000000000000000000000000000000000000000000000096800000000000000000000000000000000000000000000000000000000000009700000000000000000000000000000000000000000000000000000000000000978000000000000000000000000000000000000000000000000000000000000098000000000000000000000000000000000000000000000000000000000000009880000000000000000000000000000000000000000000000000000000000000990000000000000000000000000000000000000000000000000000000000000099800000000000000000000000000000000000000000000000000000000000009a000000000000000000000000000000000000000000000000000000000000009a800000000000000000000000000000000000000000000000000000000000009b000000000000000000000000000000000000000000000000000000000000009b800000000000000000000000000000000000000000000000000000000000009c000000000000000000000000000000000000000000000000000000000000009c800000000000000000000000000000000000000000000000000000000000009d000000000000000000000000000000000000000000000000000000000000009d800000000000000000000000000000000000000000000000000000000000009e000000000000000000000000000000000000000000000000000000000000009e800000000000000000000000000000000000000000000000000000000000009f000000000000000000000000000000000000000000000000000000000000009f80000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a080000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000000000a180000000000000000000000000000000000000000000000000000000000000a200000000000000000000000000000000000000000000000000000000000000a280000000000000000000000000000000000000000000000000000000000000a300000000000000000000000000000000000000000000000000000000000000a380000000000000000000000000000000000000000000000000000000000000a400000000000000000000000000000000000000000000000000000000000000a480000000000000000000000000000000000000000000000000000000000000a500000000000000000000000000000000000000000000000000000000000000a580000000000000000000000000000000000000000000000000000000000000a600000000000000000000000000000000000000000000000000000000000000a680000000000000000000000000000000000000000000000000000000000000a700000000000000000000000000000000000000000000000000000000000000a780000000000000000000000000000000000000000000000000000000000000a800000000000000000000000000000000000000000000000000000000000000a880000000000000000000000000000000000000000000000000000000000000a900000000000000000000000000000000000000000000000000000000000000a980000000000000000000000000000000000000000000000000000000000000aa00000000000000000000000000000000000000000000000000000000000000aa80000000000000000000000000000000000000000000000000000000000000ab00000000000000000000000000000000000000000000000000000000000000ab80000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000ac80000000000000000000000000000000000000000000000000000000000000ad00000000000000000000000000000000000000000000000000000000000000ad80000000000000000000000000000000000000000000000000000000000000ae00000000000000000000000000000000000000000000000000000000000000ae80000000000000000000000000000000000000000000000000000000000000af00000000000000000000000000000000000000000000000000000000000000af80000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000b080000000000000000000000000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000b180000000000000000000000000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000b280000000000000000000000000000000000000000000000000000000000000b300000000000000000000000000000000000000000000000000000000000000b380000000000000000000000000000000000000000000000000000000000000b400000000000000000000000000000000000000000000000000000000000000b480000000000000000000000000000000000000000000000000000000000000b500000000000000000000000000000000000000000000000000000000000000b580000000000000000000000000000000000000000000000000000000000000b600000000000000000000000000000000000000000000000000000000000000b680000000000000000000000000000000000000000000000000000000000000b700000000000000000000000000000000000000000000000000000000000000b780000000000000000000000000000000000000000000000000000000000000b800000000000000000000000000000000000000000000000000000000000000b880000000000000000000000000000000000000000000000000000000000000b900000000000000000000000000000000000000000000000000000000000000b980000000000000000000000000000000000000000000000000000000000000ba00000000000000000000000000000000000000000000000000000000000000ba80000000000000000000000000000000000000000000000000000000000000bb00000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000000bc80000000000000000000000000000000000000000000000000000000000000bd00000000000000000000000000000000000000000000000000000000000000bd80000000000000000000000000000000000000000000000000000000000000be00000000000000000000000000000000000000000000000000000000000000be80000000000000000000000000000000000000000000000000000000000000bf00000000000000000000000000000000000000000000000000000000000000bf80000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c080000000000000000000000000000000000000000000000000000000000000c100000000000000000000000000000000000000000000000000000000000000c180000000000000000000000000000000000000000000000000000000000000c200000000000000000000000000000000000000000000000000000000000000c280000000000000000000000000000000000000000000000000000000000000c300000000000000000000000000000000000000000000000000000000000000c380000000000000000000000000000000000000000000000000000000000000c400000000000000000000000000000000000000000000000000000000000000c480000000000000000000000000000000000000000000000000000000000000c500000000000000000000000000000000000000000000000000000000000000c580000000000000000000000000000000000000000000000000000000000000c600000000000000000000000000000000000000000000000000000000000000c680000000000000000000000000000000000000000000000000000000000000c700000000000000000000000000000000000000000000000000000000000000c780000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000c880000000000000000000000000000000000000000000000000000000000000c900000000000000000000000000000000000000000000000000000000000000c980000000000000000000000000000000000000000000000000000000000000ca00000000000000000000000000000000000000000000000000000000000000ca80000000000000000000000000000000000000000000000000000000000000cb00000000000000000000000000000000000000000000000000000000000000cb80000000000000000000000000000000000000000000000000000000000000cc00000000000000000000000000000000000000000000000000000000000000cc80000000000000000000000000000000000000000000000000000000000000cd00000000000000000000000000000000000000000000000000000000000000cd80000000000000000000000000000000000000000000000000000000000000ce00000000000000000000000000000000000000000000000000000000000000ce80000000000000000000000000000000000000000000000000000000000000cf00000000000000000000000000000000000000000000000000000000000000cf80000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000d080000000000000000000000000000000000000000000000000000000000000d100000000000000000000000000000000000000000000000000000000000000d180000000000000000000000000000000000000000000000000000000000000d200000000000000000000000000000000000000000000000000000000000000d280000000000000000000000000000000000000000000000000000000000000d300000000000000000000000000000000000000000000000000000000000000d380000000000000000000000000000000000000000000000000000000000000d400000000000000000000000000000000000000000000000000000000000000d480000000000000000000000000000000000000000000000000000000000000d500000000000000000000000000000000000000000000000000000000000000d580000000000000000000000000000000000000000000000000000000000000d600000000000000000000000000000000000000000000000000000000000000d680000000000000000000000000000000000000000000000000000000000000d700000000000000000000000000000000000000000000000000000000000000d780000000000000000000000000000000000000000000000000000000000000d800000000000000000000000000000000000000000000000000000000000000d880000000000000000000000000000000000000000000000000000000000000d900000000000000000000000000000000000000000000000000000000000000d980000000000000000000000000000000000000000000000000000000000000da00000000000000000000000000000000000000000000000000000000000000da80000000000000000000000000000000000000000000000000000000000000db00000000000000000000000000000000000000000000000000000000000000db80000000000000000000000000000000000000000000000000000000000000dc00000000000000000000000000000000000000000000000000000000000000dc80000000000000000000000000000000000000000000000000000000000000dd00000000000000000000000000000000000000000000000000000000000000dd80000000000000000000000000000000000000000000000000000000000000de00000000000000000000000000000000000000000000000000000000000000de80000000000000000000000000000000000000000000000000000000000000df00000000000000000000000000000000000000000000000000000000000000df80000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000e080000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000000000000000e180000000000000000000000000000000000000000000000000000000000000e200000000000000000000000000000000000000000000000000000000000000e280000000000000000000000000000000000000000000000000000000000000e300000000000000000000000000000000000000000000000000000000000000e380000000000000000000000000000000000000000000000000000000000000e400000000000000000000000000000000000000000000000000000000000000e480000000000000000000000000000000000000000000000000000000000000e500000000000000000000000000000000000000000000000000000000000000e580000000000000000000000000000000000000000000000000000000000000e600000000000000000000000000000000000000000000000000000000000000e680000000000000000000000000000000000000000000000000000000000000e700000000000000000000000000000000000000000000000000000000000000e780000000000000000000000000000000000000000000000000000000000000e800000000000000000000000000000000000000000000000000000000000000e880000000000000000000000000000000000000000000000000000000000000e900000000000000000000000000000000000000000000000000000000000000e980000000000000000000000000000000000000000000000000000000000000ea00000000000000000000000000000000000000000000000000000000000000ea80000000000000000000000000000000000000000000000000000000000000eb00000000000000000000000000000000000000000000000000000000000000eb80000000000000000000000000000000000000000000000000000000000000ec00000000000000000000000000000000000000000000000000000000000000ec80000000000000000000000000000000000000000000000000000000000000ed00000000000000000000000000000000000000000000000000000000000000ed80000000000000000000000000000000000000000000000000000000000000ee00000000000000000000000000000000000000000000000000000000000000ee80000000000000000000000000000000000000000000000000000000000000ef00000000000000000000000000000000000000000000000000000000000000ef80000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000000f080000000000000000000000000000000000000000000000000000000000000f100000000000000000000000000000000000000000000000000000000000000f180000000000000000000000000000000000000000000000000000000000000f200000000000000000000000000000000000000000000000000000000000000f280000000000000000000000000000000000000000000000000000000000000f300000000000000000000000000000000000000000000000000000000000000f380000000000000000000000000000000000000000000000000000000000000f400000000000000000000000000000000000000000000000000000000000000f480000000000000000000000000000000000000000000000000000000000000f500000000000000000000000000000000000000000000000000000000000000f580000000000000000000000000000000000000000000000000000000000000f600000000000000000000000000000000000000000000000000000000000000f680000000000000000000000000000000000000000000000000000000000000f700000000000000000000000000000000000000000000000000000000000000f780000000000000000000000000000000000000000000000000000000000000f800000000000000000000000000000000000000000000000000000000000000f880000000000000000000000000000000000000000000000000000000000000f900000000000000000000000000000000000000000000000000000000000000f980000000000000000000000000000000000000000000000000000000000000fa00000000000000000000000000000000000000000000000000000000000000fa80000000000000000000000000000000000000000000000000000000000000fb00000000000000000000000000000000000000000000000000000000000000fb80000000000000000000000000000000000000000000000000000000000000fc00000000000000000000000000000000000000000000000000000000000000fc80000000000000000000000000000000000000000000000000000000000000fd00000000000000000000000000000000000000000000000000000000000000fd80000000000000000000000000000000000000000000000000000000000000fe00000000000000000000000000000000000000000000000000000000000000fe80000000000000000000000000000000000000000000000000000000000000ff00000000000000000000000000000000000000000000000000000000000000ff800000000000000000000000000000000000000000000000000000000
LUTSelector Luminance
GevStreamChannelSelector    StreamChannel0
GevSCPSPacketSize   1500
GevStreamChannelSelector    StreamChannel0
GevStreamChannelSelector    StreamChannel0
GevSCPD 0
GevStreamChannelSelector    StreamChannel0
GevStreamChannelSelector    StreamChannel0
GevSCFTD    0
GevStreamChannelSelector    StreamChannel0
GevStreamChannelSelector    StreamChannel0
GevSCBWR    20
GevStreamChannelSelector    StreamChannel0
GevStreamChannelSelector    StreamChannel0
GevSCBWRA   1
GevStreamChannelSelector    StreamChannel0
AutoTargetValue 128
GrayValueAdjustmentDampingRaw   768
BalanceWhiteAdjustmentDampingRaw    1000
AutoGainRawLowerLimit   256
AutoGainRawUpperLimit   2047
AutoExposureTimeAbsLowerLimit   2
AutoExposureTimeAbsUpperLimit   1000
AutoFunctionProfile ExposureMinimum
AutoFunctionAOISelector AOI1
AutoFunctionAOIWidth    2048
AutoFunctionAOISelector AOI2
AutoFunctionAOIWidth    2048
AutoFunctionAOISelector AOI1
AutoFunctionAOISelector AOI1
AutoFunctionAOIHeight   128
AutoFunctionAOISelector AOI2
AutoFunctionAOIHeight   128
AutoFunctionAOISelector AOI1
AutoFunctionAOISelector AOI1
AutoFunctionAOIOffsetX  0
AutoFunctionAOISelector AOI2
AutoFunctionAOIOffsetX  0
AutoFunctionAOISelector AOI1
AutoFunctionAOISelector AOI1
AutoFunctionAOIOffsetY  0
AutoFunctionAOISelector AOI2
AutoFunctionAOIOffsetY  0
AutoFunctionAOISelector AOI1
ShadingSelector OffsetShading
ShadingEnable   0
ShadingSelector GainShading
ShadingEnable   0
ShadingSelector GainShading
UserDefinedValueSelector    Value1
UserDefinedValue    0
UserDefinedValueSelector    Value2
UserDefinedValue    0
UserDefinedValueSelector    Value3
UserDefinedValue    0
UserDefinedValueSelector    Value4
UserDefinedValue    0
UserDefinedValueSelector    Value5
UserDefinedValue    0
UserDefinedValueSelector    Value1
ParameterSelector   Gain
RemoveLimits    0
ParameterSelector   AutoTargetValue
RemoveLimits    0
ParameterSelector   ExposureOverhead
RemoveLimits    0
ParameterSelector   ExposureOverlapMax
RemoveLimits    0
ParameterSelector   Gain
ExpertFeatureAccessSelector ExpertFeature1
ExpertFeatureEnable 0
ExpertFeatureAccessSelector ExpertFeature1
ExpertFeatureEnable 0
ExpertFeatureAccessSelector ExpertFeature1
ChunkModeActive 0
EventSelector   LineStartOvertrigger
EventNotification   Off
EventSelector   FrameStartOvertrigger
EventNotification   Off
EventSelector   AcquisitionStartOvertrigger
EventNotification   Off
EventSelector   FrameTimeout
EventNotification   Off
EventSelector   ActionLate
EventNotification   Off
EventSelector   EventOverrun
EventNotification   Off
EventSelector   FrameStartOvertrigger
thiesmoeller commented 4 months ago

a) could you move to the upcoming pypylon 4.0 ( available as 4.0.0rc2 on pypi) so we can check with latest fixes we fixed part of the zerocopy handling and we link to latest pylon gigevision drivers b) can you run your application using heaptrack

    apt-get install heaptrack heaptrack_gui

this will alow you to generate a fine grained trace of the main allocators that leak in your example

thiesmoeller commented 4 months ago

You set GevSCPD 0 this is the delay time between gigevision packets. As your camera is capable to sent packets with the minimum inter packet gap of 96ns your receiver NIC and Linux kernel stack might be overrun.

The typical procedure to set this value is described here: https://docs.baslerweb.com/knowledge/how-to-troubleshoot-lost-packets-or-frames-while-using-gige-cameras

The idea is to increase the space between network packets ( and thus decrease the pressure on your hardware and software stack ) up to the point the virtual framerate of your linescan camera decreases.

I see, that you set a very very large number of buffers in your application. In a gigevision use case, where there is always a small packet queue to the hardware and from there the data is copied to your application buffers. So adding more buffers in a continous acquisition use case is only needed, if your image processing sporadically is slower than the incoming image rate and you have to be sure that there will always buffers ready to be filled by the hardware packet queue.

Jannick-v commented 4 months ago

Hi @thiesmoeller Thanks for the reply and explanation. The increased number of buffers is because we were experiencing corrupt lines from time to time (there were sections of the image that were just completely overwritten by the data content of another image) in pypylon 1.9.

The following error message in pypylon 1.9 made us increase all these buffers.

3774873620: The buffer was incompletely grabbed. This can be caused by performance problems of the network hardware used, i.e., the network adapter, switch, or Ethernet cable. Buffer underruns can also cause image loss. To fix this, use the pylonGigEConfigurator tool to optimize your setup and use more buffers for grabbing in your application to prevent buffer underruns.

I must admit that I am not fully understanding how all the buffer handling, loading and offloading works behind the scenes. I once found a document that was high-level describing the internals, but I currently fail to find it back. If you know where to find it, please share :)

We upgraded to pypylon 3.0.1 and also installed the pylon distribution. The error message changed a little, pointing exactly to the GevSCPD parameter you already mentioned in your reply :muscle: I have had to change the parameter to 125000 ticks , which is the equivalent of 1 ms for our camera to get things to work in the full application (which runs in a k3s pod). The value is rather high, but it seems to work..

The buffer was incompletely grabbed. This can be caused by performance problems of the network hardware used, i.e. network adapter, switch, or ethernet cable. To fix this, try increasing the camera's Inter-Packet Delay in the Transport Layer category

Last but not least, I finally found the time to do a quick test. I will e-mail the heaptrack file (since I cannot upload it to git)

thiesmoeller commented 4 months ago

For your target k3s environment: Which CNI do you use and in which configuration?

Buffer management is explained here https://docs.baslerweb.com/pylonapi/cpp/pylon_programmingguide#the-default-grab-strategy-one-by-one

Jannick-v commented 4 months ago

Thanks for the link! I hope you have succesfully received the file? We have an open support ticket (ref 74135710, + I took the liberty to already include you in mail trace) with more details, but currently we have the following:

We have tried different k3s flannel, multus, macvlan versions and different cni spec versions but without success. Eventually, the below combo (which does not necessarily mean that we use the latest versions) + pypylon 1.9.0 + GevSCPD 125000 seems to be the most stable combo so far.

mic-733ao@ubuntu:~$ /var/lib/rancher/k3s/data/current/bin/multus --version
multus: version:v4.0.2(clean,released), commit:f03765681fe81ee1e0633ee1734bf48ab3bccf2b, date:2023-05-25T13:40:20+00:00

mic-733ao@ubuntu:~$ /var/lib/rancher/k3s/data/current/bin/flannel 
CNI Plugin flannel version v0.18.1 (linux/arm64) commit 990ba0e88c90f8ed8b50e0ccd375937b841b176e built on 2022-07-19T01:08:03Z

mic-733ao@ubuntu:~$ /var/lib/rancher/k3s/data/current/bin/macvlan 
CNI macvlan plugin v1.5.1
CNI protocol versions supported: 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.4.0, 1.0.0

mic-733ao@ubuntu:~$ k3s --version
k3s version v1.24.3+k3s1 (990ba0e8)
go version go1.18.1
root@ubuntu:/home/mic-733ao# kubectl -n kube-system get network-attachment-definition macvlan-local-link -o yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  annotations:
    objectset.rio.cattle.io/applied: H4sIAAAAAAAA/4yRTYvbQAyG/4rR2XbtfJjY0EOgt0KPPfkiy5pk6rHGeFSHEPLfy9TZZVlI2OO8D3r0irkBTvY3z8F6gQaGQ8hJbE5CJrf+21JCCoOVHhr4xXrx83BURTqPLPqDjRWrcTKFkRV7VITmBijiFSMI8em7P0waWPPZ+pxQ1XGU22iF9Cn3F+E5Oy1DLLYNH8hSpslPK/33Y9//3/5aITgyNDAiLQ4lE9YM36/40nSYkKJi+NtxFq5BeYR7Cg47di9vPGM4QwO1MUXRmZq7/WZfmaIiQ1WPSFsy1bas8dCXvKt3UfqprfOELnNWBljZky5hYopNyIuxJ2jglrRA8va5LTRJC0W+y4sW0qQFvU68ho9NazxiUJ5X4FA2jxTu938BAAD//7Okz+grAgAA
    objectset.rio.cattle.io/id: ""
    objectset.rio.cattle.io/owner-gvk: k3s.cattle.io/v1, Kind=Addon
    objectset.rio.cattle.io/owner-name: macvlan-net-attachment
    objectset.rio.cattle.io/owner-namespace: kube-system
  creationTimestamp: "2024-07-02T16:48:41Z"
  generation: 7
  labels:
    objectset.rio.cattle.io/hash: 9ff00bf9eb5256f06cfc6daac3cf6319a8d1e494
  name: macvlan-local-link
  namespace: kube-system
  resourceVersion: "61489"
  uid: f4d81b2b-cf3b-4f47-846a-71661c6824de
spec:
  config: '{ "cniVersion": "0.4.0", "type": "macvlan", "master": "lan2", "mode": "bridge",
    "mtu": 9000, "ipam": { "type": "host-local", "ranges": [ [ { "subnet": "169.254.0.0/16",
    "rangeStart": "169.254.184.200", "rangeEnd": "169.254.184.220" } ] ] } }'

Because we are nearing the project deadline, I have little room to keep on changing and testing things. Nevertheless, I still would like to see how we could improve in the future, so I am all ears :)

edit: add more version info

thiesmoeller commented 4 months ago

There is no significant memory leak in your trace. Only leaks are in python itself ( maybe false positive )

You allocate in your code 10000 Buffers of 420x800 pix Mono8 and end up with 3.4GB Memory. image

I assume, that you run into this, when your docker/k3s env fails

Jannick-v commented 4 months ago

haha ok, that's pretty embarrassing :sweat_smile: just did a test without the set_buffer_sizes and can confirm.

We are still looking into the networking part, because an inter packet delay of 1 ms still seems pretty high..

thiesmoeller commented 4 months ago

Using MacVlan as cni in your case should give you the right performance.

Important is to use a CNI that routes the packets as early as possible into the pod.

Take care to increase the Rx mem size as you did.

Explanation to why it was not working with packet delay 0 and chunks:

The image data was " naturally" throttled by the line rate of your sensor. The chunks are send from camera buffers at full speed at the end of the transfer and are too close back to back for your host

Jannick-v commented 4 months ago

All right. Thanks for the explanation. Very much appreciated. I think we can close this issue, since it was a False alarm.