hardbyte / hardbyte/python-can

Poor PCAN Peak performance

Aberta
#1,685 9 comentários 0 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
Python
Estrelas
1.6k
Forks
697
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

### Describe the bug
To put it simply, I have a script that implements a simple protocol to flash a device via canbus. I'm using the python-can library, and have access to a PCAN peak and a VN1630 from Vector. Very easy to use, just change the interface and channel (at a speed of 500k, can non-fd, every other setting is the default) and the script works flawlessly with both hardware devices.
The problem I'm having is actually with performance: with no modifications to the script (except obviously to the channel and interface), with the PCAN Peak the bus usage sits at around 30%, and with the VN1630 at around 74%. Obviously the latter finishes much quicker. I tried profiling using cProfile and Snakeviz to visualize the results, and here they are:

Using the PCAN Peak:
![image](https://github.com/hardbyte/python-can/assets/61554895/aa1af186-5ba3-4325-a5ad-10a42932b44d)

Using the Vector VN1630:
![image](https://github.com/hardbyte/python-can/assets/61554895/5f9daf9c-ad74-44e6-aed7-059d236e69fb)

As you can see, the vast majority of the time in both cases is spent inside the `_winapi.WaitForSingleObject` call; and in fact, being called approx. 82k times in both cases, with the Peak the "percall" time is much higher than with the VN1630.

Am I missing something? Is this due to some driver implementation detail? Can this be fixed/improved/circumvented without touching the device's drivers?

### To Reproduce
I'll link both `.prof` files in case anyone else want to take a look at it:
[programperf.zip](https://github.com/hardbyte/python-can/files/13166237/programperf.zip)

### Expected behavior
The performance of both devices should match, or at least not be so great.

### Additional context

OS and version: Windows 10
Python version: 3.11.3
python-can version: 4.2.2

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece reproduzindo a diferença de desempenho no Windows 10 com o script fornecido e compare os dois perfis em programperf.zip. Determine se o comportamento mais lento de _winapi.WaitForSingleObject está no python-can ou no driver PCAN; em seguida, documente uma correção ou solução alternativa com escopo definido e verifique se a utilização do barramento melhora.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
embedded-iot, networking
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Pouca atividade
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
42/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.