Hassibayub
Posts: 11
Joined: Thu Oct 17, 2019 8:24 pm

Re: Which OS is the fastest ?

Sat Jul 11, 2020 12:12 pm

neilgl wrote:
Sat Jul 11, 2020 12:06 pm
SSD = Solid State Disk
(you may find this most immature question but...) would ssd enhance performance drastically or just the slight effect?
Please share your experience. I'm really interested in this option.

Hassibayub
Posts: 11
Joined: Thu Oct 17, 2019 8:24 pm

Re: Which OS is the fastest ?

Sat Jul 11, 2020 12:13 pm

LTolledo wrote:
Sat Jul 11, 2020 12:02 pm
you need bare metal programming for that....
its nearly impossible to do such power pythonic stuff with bare programming.. dont you think?

User avatar
neilgl
Posts: 2342
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Which OS is the fastest ?

Sat Jul 11, 2020 12:19 pm

SSD boots faster

User avatar
rpiMike
Posts: 1432
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Which OS is the fastest ?

Sat Jul 11, 2020 12:21 pm

I would suggest getting a Pi4 and working out why you can’t get OpenCV working before trying SSD.

jahboater
Posts: 5928
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Which OS is the fastest ?

Sat Jul 11, 2020 12:23 pm

Hassibayub wrote:
Sat Jul 11, 2020 12:04 pm
I'm using Raspberry pi 3b+.
That's easy then. Get a Pi4.
The 3B+ runs at 1.4GHz, the Pi4 has more advanced CPU's (Cortex-A72) that easily run at 2GHz or more.
The SD card access is twice as fast, the ethernet is full GIGe, there are two USB3 ports, the memory is many times faster and bigger, video is much more capable (2 x 4k), and so on. All round speed improvements - for the same size and price.

Slow SD card?
how can I find if my sd card is slow or not?
I would just get a Sandisk A1 class card.
Later if SD card access is still an issue, get USB3 attached SSD.

A Pi4 with lots of memory (up to 8GB) will have plenty spare for a large disk cache, so slow disks should be less of a problem.
Even the base $35 model of the Pi4 has 2GB of memory!
Pi4 8GB running PIOS64 Lite

Rascas
Posts: 697
Joined: Tue Mar 11, 2014 6:18 pm
Location: Porto, Portugal
Contact: Website

Re: Which OS is the fastest ?

Sat Jul 11, 2020 1:04 pm

If your python program is using only 25% CPU it is because it is single thread. Make it multithreaded to use all 4 cores and it will be about 4 times faster.
Don't know your program code, but getting a faster microsd or one SSD will give you only a fraction of speed if any at all.
Last edited by Rascas on Sat Jul 11, 2020 4:52 pm, edited 1 time in total.

User avatar
B.Goode
Posts: 10404
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Which OS is the fastest ?

Sat Jul 11, 2020 1:54 pm

Hassibayub wrote:
Sat Jul 11, 2020 12:13 pm
LTolledo wrote:
Sat Jul 11, 2020 12:02 pm
you need bare metal programming for that....
its nearly impossible to do such power pythonic stuff with bare programming.. dont you think?

So there is your dilemma summed up in a sentence. Your level of programming competence is such that you need the convenience of an interpreted language such as Python which carries with it a performance penalty.

To write 'tighter' more efficient ( = 'faster' ) code might require a compiled language such as C or one or its successors, which you feel is currently beyond your ability.

Two possible solutions -

Throw more CPU power at the problem;

Invest in learning how to write more efficient code.


Perhaps much of the growth in the Computing sector of the semiconductor industry over the last two decades or more has been in large part driven by people adopting the first solution...

bjtheone
Posts: 896
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Which OS is the fastest ?

Sat Jul 11, 2020 4:45 pm

Hassibayub wrote:
Sat Jul 11, 2020 12:04 pm
rpdom wrote:
Sat Jul 11, 2020 11:51 am
If you need fast responses, then maybe Python is not the language you should be using. There is a reason most of the code in Linux is written in C or C++. Even many of the Python library routines are written in C.
C++ is the option i'm aware of but you know when a project like iris recognition system, it is better to use powerful python rather than c++ which is hard to write and not easy for intensive projects.
Python is an interpreted language and as such is always going to be slower than C++ (which is compiled). Python itself is actually written in C. It certainly may be easier for you to write in Python but C or C++ is (a) more powerful and (b) faster.

W. H. Heydt
Posts: 12962
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Which OS is the fastest ?

Sat Jul 11, 2020 5:07 pm

Hassibayub wrote:
Sat Jul 11, 2020 11:41 am
I look at task manager in raspberry pi I see it only takes a 25% process. I want that somehow it takes complete resources (90-100%) to run my program faster.
Given what you're running, that "25%" is probably 100% of one core (of 4 CPU cores your Pi has). If there is anything you can do to run parts of your program in parallel (so those parts will be scheduled on different CPU cores) it might run faster.

User avatar
malchore
Posts: 5
Joined: Wed Jul 01, 2020 4:22 pm
Location: Twin Cities, MN (USA)
Contact: YouTube

Re: Which OS is the fastest ?

Sat Jul 11, 2020 5:22 pm

The OP (original poster) said it was a run time difference of 10 secs vs 1.5 secs on a "laptop". And no one thought to ask him what specs the laptop was using? :shock:

If his laptop was using a much newer Intel 4GHz chip, that might explain the single-core runtime difference. Intel is still the king (circa July 2020) for single-core speed. (Sidenote: That's the one and only spec AMD has to resolve before Intel becomes the AMD of 10 years ago.)

Anyways to the OP - Your python code sounds like it's almost certainly single-threaded. (By the way, it's the same on your laptop as well.) Rewrite the python code to take advantage of muti-threading. Can read here: https://www.tutorialspoint.com/python/p ... eading.htm

In super basic terms, you'll need to split your image into 4 peices of data and then "process" the images against the known database. OR - compare the image against 4 known images simultaneously.

As for all the previous replies to this thread - they were taking about the "speed" of your storage devices. (Disks.) If you have a lot of disk I/O while comparing images, then having "fast" disk read speeds could speed up the performance of your Iris scan considerably on the Raspberry Pi.

And lastly, if the OS version of your Raspberry Pi OS is 32-bit vs. 64-bit OS on your laptop, which python libraries are in use? I'm very new to Python but there might be speed trade-offs between 32-bit and 64-bit libraries. (I can very well be wrong on this front.)

User avatar
B.Goode
Posts: 10404
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Which OS is the fastest ?

Sat Jul 11, 2020 5:32 pm

malchore wrote:
Sat Jul 11, 2020 5:22 pm

As for all the previous replies to this thread - they were taking about the "speed" of your storage devices. (Disks.)

Factually incorrect.

User avatar
malchore
Posts: 5
Joined: Wed Jul 01, 2020 4:22 pm
Location: Twin Cities, MN (USA)
Contact: YouTube

Re: Which OS is the fastest ?

Sat Jul 11, 2020 5:37 pm

B.Goode wrote:
Sat Jul 11, 2020 5:32 pm
malchore wrote:
Sat Jul 11, 2020 5:22 pm

As for all the previous replies to this thread - they were taking about the "speed" of your storage devices. (Disks.)

Factually incorrect.
If my use of the word "all" is what you're commenting on, then I'll stipulate.

cleverca22
Posts: 978
Joined: Sat Aug 18, 2012 2:33 pm

Re: Which OS is the fastest ?

Sat Jul 11, 2020 6:02 pm

Hassibayub wrote:
Sat Jul 11, 2020 11:41 am
I've created an iris Recognition program that takes a picture, applies some mathematics to extract feature, and converts it to binary code.
When I verify a user (whether it exists in the system or not) if exits then unlock the locker.
In verify.py it take 10secs while on my laptop it barely takes 1.5secs. and you know 10sec is huge.

I look at task manager in raspberry pi I see it only takes a 25% process. I want that somehow it takes complete resources (90-100%) to run my program faster.

PS: I tried to define my problem in short work. If you want more elaboration, pls let me know. :) :)
if its a quad-core pi, then its highly likely that your program is single-threaded, and maxing out one cpu core
to make it any faster, you need to modify the algo to run in a multi-threaded manner

for example, split the image up into 4 pieces, and then fire off a thread to compute each piece in parallel, and then re-assemble all of the data at the end

it doesnt really matter which OS you use at that point, because the bottleneck is just in the arm core processing data

User avatar
bensimmo
Posts: 4723
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Which OS is the fastest ?

Sat Jul 11, 2020 8:24 pm

I think in python you'll need to move to the multiprocessing module to use all cores and not just the threading module.
Normal Python3 just sits on one core, as mentioned earlier and by design, that's why you are seeing 25%. one whole core being used.

That's the way of python.

look for alternatives.


Your PC is also probably much faster.


why not time each section of code on the Pi and the PC and see where in your code it is slowest.

or stick the code up on GitHub or similar and see if anyone can help out.or see obvious slow parts.

W. H. Heydt
Posts: 12962
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Which OS is the fastest ?

Sat Jul 11, 2020 8:59 pm

It is now clear that this thread has nothing whatsoever to do with the relative performance of the OS running on the OPs Pi, and everything to do with the performance of a single-threaded Python program.

This leaves several areas to look at for optimization. First, choice of language processing method. If I am not mistaken, there are ways to actually compile Python programs instead of running everything through an interpreter. Second, rewrite the program in a more efficient language than Python, such as C or C++. Third, rewrite the code to multi-thread it as much as possible to take advantage of having multiple CPU cores. Fourth, get a newer generation of Pi, substituting a Pi4B for the present Pi3B. Fifth, overclock the Pi.

jahboater
Posts: 5928
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Which OS is the fastest ?

Sat Jul 11, 2020 11:42 pm

W. H. Heydt wrote:
Sat Jul 11, 2020 8:59 pm
This leaves several areas to look at for optimization. First, choice of language processing method. If I am not mistaken, there are ways to actually compile Python programs instead of running everything through an interpreter. Second, rewrite the program in a more efficient language than Python, such as C or C++. Third, rewrite the code to multi-thread it as much as possible to take advantage of having multiple CPU cores. Fourth, get a newer generation of Pi, substituting a Pi4B for the present Pi3B. Fifth, overclock the Pi.
Methods Four and Five require the least effort and no code changes I would suggest.
Pi4 8GB running PIOS64 Lite

W. H. Heydt
Posts: 12962
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Which OS is the fastest ?

Sun Jul 12, 2020 12:21 am

jahboater wrote:
Sat Jul 11, 2020 11:42 pm
W. H. Heydt wrote:
Sat Jul 11, 2020 8:59 pm
This leaves several areas to look at for optimization. First, choice of language processing method. If I am not mistaken, there are ways to actually compile Python programs instead of running everything through an interpreter. Second, rewrite the program in a more efficient language than Python, such as C or C++. Third, rewrite the code to multi-thread it as much as possible to take advantage of having multiple CPU cores. Fourth, get a newer generation of Pi, substituting a Pi4B for the present Pi3B. Fifth, overclock the Pi.
Methods Four and Five require the least effort and no code changes I would suggest.
Also known as "throw hardware at the problem." That works right up until you're using the best available hardware, and if it isn't enough, you're back to trying to improve the software.

Option three (change the code to multithread) has the greatest potential for improvement, but is probably the most difficult to achieve.

cleverca22
Posts: 978
Joined: Sat Aug 18, 2012 2:33 pm

Re: Which OS is the fastest ?

Sun Jul 12, 2020 2:38 am

writing it in C also doesnt have to be an all or nothing thing

https://docs.python.org/2/extending/extending.html

you can write just one function in C, then call it from normal python, and move the slow parts over, ive also done it in the past to call X11 api stuff, when i didnt want to bother learning the python bindings, and i already had a working C example to start from

User avatar
rpdom
Posts: 17424
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Which OS is the fastest ?

Sun Jul 12, 2020 5:58 am

W. H. Heydt wrote:
Sun Jul 12, 2020 12:21 am
you're back to trying to improve the software.
Which can often give the best results.

For example for quite a few years now I've had a web page that shows me a graph of temperatures around my house for the current day. It runs under Apache on a Pi 2B. It has always taken about 10-15 seconds to load.

I always assumed that this was because PHP was taking a long time to query the database and plot the graph. I was considering moving the website to a Pi 4B to run it faster.

A couple of weeks ago I decided to find out which of the DB queries were causing the slowdown. So I checked each one manually on the MySQL CLI.

To my surprise all of the graph plotting queries were fast. The one that took ages was an almost insignificant one that just reported the current temperature outdoors in the summary area of the plot. I tweaked the SQL on that query a little and it now takes less than 0.5 seconds to generate that page. I think that when I originally wrote the code there was hardly any data on the database, so it ran fast enough, but now there is some years worth of data on there it takes a lot longer with the old query method.
Unreadable squiggle

Hassibayub
Posts: 11
Joined: Thu Oct 17, 2019 8:24 pm

Re: Which OS is the fastest ?

Sun Jul 12, 2020 6:39 am

Rascas wrote:
Sat Jul 11, 2020 1:04 pm
If your python program is using only 25% CPU it is because it is single thread. Make it multithreaded to use all 4 cores and it will be about 4 times faster.
Don't know your program code, but getting a faster microsd or one SSD will give you only a fraction of speed if any at all.
Great! you pointed at the right direction! All I need to do is use multithreading in python... Thank you.!

Hassibayub
Posts: 11
Joined: Thu Oct 17, 2019 8:24 pm

Re: Which OS is the fastest ?

Sun Jul 12, 2020 6:53 am

malchore wrote:
Sat Jul 11, 2020 5:22 pm
The OP (original poster) said it was a run time difference of 10 secs vs 1.5 secs on a "laptop". And no one thought to ask him what specs the laptop was using? :shock:

If his laptop was using a much newer Intel 4GHz chip, that might explain the single-core runtime difference. Intel is still the king (circa July 2020) for single-core speed. (Sidenote: That's the one and only spec AMD has to resolve before Intel becomes the AMD of 10 years ago.)
Exactly. my laptop is newer intel processor and Im running a 64bit processor. :ugeek:
Anyways to the OP - Your python code sounds like it's almost certainly single-threaded. (By the way, it's the same on your laptop as well.) Rewrite the python code to take advantage of muti-threading. Can read here: https://www.tutorialspoint.com/python/p ... eading.htm
Now someone got the problem and driving me into the right direction. Will surely check the link and learn how to use multithreading.
In super basic terms, you'll need to split your image into 4 peices of data and then "process" the images against the known database. OR - compare the image against 4 known images simultaneously.

As for all the previous replies to this thread - they were taking about the "speed" of your storage devices. (Disks.) If you have a lot of disk I/O while comparing images, then having "fast" disk read speeds could speed up the performance of your Iris scan considerably on the Raspberry Pi.

And lastly, if the OS version of your Raspberry Pi OS is 32-bit vs. 64-bit OS on your laptop, which python libraries are in use? I'm very new to Python but there might be speed trade-offs between 32-bit and 64-bit libraries. (I can very well be wrong on this front.)
Thank you so very much. your post really help to find out the problem. I liked the way you explained the multithread is easy and understandable.

Hassibayub
Posts: 11
Joined: Thu Oct 17, 2019 8:24 pm

Re: Which OS is the fastest ?

Sun Jul 12, 2020 7:06 am

rpdom wrote:
Sun Jul 12, 2020 5:58 am
W. H. Heydt wrote:
Sun Jul 12, 2020 12:21 am
you're back to trying to improve the software.
To my surprise all of the graph plotting queries were fast. The one that took ages was an almost insignificant one that just reported the current temperature outdoors in the summary area of the plot. I tweaked the SQL on that query a little and it now takes less than 0.5 seconds to generate that page. I think that when I originally wrote the code there was hardly any data on the database, so it ran fast enough, but now there is some years worth of data on there it takes a lot longer with the old query method.
I'll check each of the section manually to see which one is taking most of the time. i'll write that section in c language as mentioned in https://docs.python.org/3.8/extending/extending.html. and make my code run for multi-threads.

if I sum up everyone's suggestion then I can say the problem is in my code rather than changing my hardware.

jahboater
Posts: 5928
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Which OS is the fastest ?

Sun Jul 12, 2020 9:04 am

W. H. Heydt wrote:
Sun Jul 12, 2020 12:21 am
Also known as "throw hardware at the problem." That works right up until you're using the best available hardware, and if it isn't enough, you're back to trying to improve the software.
True. But I repeat, its risk free and near zero effort, no code change, for quite a large gain.
Learning C and translating part, or all, of the Python code to C is non-trivial, it will take time, effort, and considerable risk.
Learning threading and changing the algorithms to use it, will take time, and likely even more risk.

By "risk" I mean that after lots of work, you could end up with something that either doesn't work or has all sorts of strange and very hard to diagnose bugs. For the threading option the bugs may also be intermittent and hard to reproduce.

Even if the OP knows C, translating an expressive dynamically typed language like Python into C is no easy task.

Ask any release manager, they do not like changes to working code late in the day.

For a software fix, I agree with suggestions above: I would try to locate the 10% that is taking 90% of the time, preferably using some kind of profiling, and implement those small sections in C.
Pi4 8GB running PIOS64 Lite

Heater
Posts: 16304
Joined: Tue Jul 17, 2012 3:02 pm

Re: Which OS is the fastest ?

Sun Jul 12, 2020 10:04 am

So this thread is not about the speed of the OS. It's about a particular program.

We know nothing of said program except there was mention of iris recognition and Python somewhere.

Python itself may or may not be the problem. If that recognition task is using OpenCV libraries or Tensorflow or whatever then 99% of the work is already done in C/C++. The Python is only orchestrating things.

On the other hand if this is some home made analysis or NN or whatever written entirely in Python performance will be terrible.
Memory in C++ is a leaky abstraction .

Return to “General discussion”