Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple CAN message thread sending the cycle time is not reliable #1729

Open
xRowe opened this issue Jan 18, 2024 · 2 comments
Open

Multiple CAN message thread sending the cycle time is not reliable #1729

xRowe opened this issue Jan 18, 2024 · 2 comments

Comments

@xRowe
Copy link

xRowe commented Jan 18, 2024

Hello Developer

I am try to use the Lib to period sending message, now when I periodic sending about 35 CAN message with different ID and different sending cycle. And there is already 42 active thread. The sending period become not reliable.

In these threads, there is a message is sending defined 50ms.
The average period is seems correct, but the message are not sending with 50ms+-.
image

For now I've tried to send the same cycle messages in a thread. After done this, the active thread is 28, still have larget number.

Is there any tricky way to solved the issue?

Thank you,
Rowe

@j-c-cook
Copy link
Contributor

Could you please provide more information about your setup? The following information is minimally required to give any meaningful feedback about the statistics you've shown above:

  • hardware interface
  • python-can version
  • python script

@xRowe
Copy link
Author

xRowe commented Feb 16, 2024

@j-c-cook , Thanks for your reply.

Laptop: i5-1145G7 with 8.00 GB RAM
Python: v3.11.7
Hardware interface: Vector
python-can: v4.3.1
Example Script:

# Initial Channels
can_bus0 = can.interface.Bus(bustype='vector', channel=0, bitrate=500_000, fd=True, data_bitrate=2_000_000, bitrate_switch=True, receive_own_messages=True, app_name=None)
can_bus1 = can.interface.Bus(bustype='vector', channel=1, bitrate=500_000, fd=True, data_bitrate=2_000_000, bitrate_switch=True, receive_own_messages=True, app_name=None)
can_bus2 = can.interface.Bus(bustype='vector', channel=2, bitrate=500_000, fd=True, data_bitrate=2_000_000, bitrate_switch=True, receive_own_messages=True, app_name=None)
can_bus3 = can.interface.Bus(bustype='vector', channel=3, bitrate=500_000, fd=True, data_bitrate=2_000_000, bitrate_switch=True, receive_own_messages=True, app_name=None)

# Initial Listener for Each Channel for receiving message.
# Listener do some parse job.
_notifier0 = can.Notifier(can_bus0, [listener0], timeout=0.1)
_notifier1 = can.Notifier(can_bus1, [listener1], timeout=0.1)
_notifier2 = can.Notifier(can_bus2, [listener2], timeout=0.1)
_notifier3 = can.Notifier(can_bus3, [listener3], timeout=0.1)

# Start sending message period
can_bus0.send_period("A_2ms", 2/1000.0)
can_bus0.send_period("B_5ms", 5/1000.0)
can_bus0.send_period("C_10ms", 10/1000.0)
can_bus0.send_period("C_20ms", 20/1000.0)
can_bus0.send_period("C_50ms", 50/1000.0)
can_bus0.send_period("C_100ms", 100/1000.0)
can_bus0.send_period("C_200ms", 200/1000.0)

can_bus1.send_period("A_2ms", 2/1000.0)
can_bus1.send_period("B_5ms", 5/1000.0)
can_bus1.send_period("C_10ms", 10/1000.0)
can_bus1.send_period("C_20ms", 20/1000.0)
can_bus1.send_period("C_50ms", 50/1000.0)
can_bus1.send_period("C_100ms", 100/1000.0)
can_bus1.send_period("C_200ms", 200/1000.0)

can_bus2.send_period("A_2ms", 2/1000.0)
can_bus2.send_period("B_5ms", 5/1000.0)
can_bus2.send_period("C_10ms", 10/1000.0)
can_bus2.send_period("C_20ms", 20/1000.0)
can_bus2.send_period("C_50ms", 50/1000.0)
can_bus2.send_period("C_100ms", 100/1000.0)
can_bus2.send_period("C_200ms", 200/1000.0)

can_bus3.send_period("A_2ms", 2/1000.0)
can_bus3.send_period("B_5ms", 5/1000.0)
can_bus3.send_period("C_10ms", 10/1000.0)
can_bus3.send_period("C_20ms", 20/1000.0)
can_bus3.send_period("C_50ms", 50/1000.0)
can_bus3.send_period("C_100ms", 100/1000.0)
can_bus3.send_period("C_200ms", 200/1000.0)

time.sleep(10)


# In total 50+ thread is used for sending/receving/parsing message

In the previous snapshot, (is one of the 50ms sending message task) the sending timing monitor by CANoe.

I think the cyclic task is limited by python GIL, and I found that 50+ threading running the message period sendt with > 100ms task, its period is stable. but 2ms/5ms/10ms/20ms/50ms task/message, it works bad.
And if there is only few threads like 5, the 2ms/5ms/10ms/20ms/50ms task/message is much more stable.

Do you have any advice, what I can do in next step?

Thanks,
Rowe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants