# Poor php and python performances



## MassimoM (Sep 24, 2019)

Good morning.
I have some scripts written in python, and i have noticed that the startup time of python is much longer that in linux.
In linux the script is started in some tenths of a second, while in freebsd the script takes 4/5 seconds to start.
I'm not talking about running times (freebsd is a little faster), but the time that is needed to "wake up" python.
The same thing happens in php scripts in apache.
The script itself is ran in a tenths or hundredths of a second, but the startup time is much longer (7 or 10 seconds)


----------



## Bren (Nov 7, 2019)

I've seen the same thing. I was running my Ansible master node (which uses Python) on FreeBSD 12 and it was so slow that I had to move it to a Linux VM. I measured 4-5s startup on FreeBSD and < 1 on Linux. My FreeBSD hosts are also _much_ slower as Ansible clients than my Linux hosts. These systems are all servers with SSDs, lots of memory, fast CPUs, etc.

Does anyone have any ideas as to why this is happening?


----------



## shkhln (Nov 8, 2019)

Jerry said:


> Does anyone have any ideas as to why this is happening?



No, why should we? If it were a common issue, it would be on the bug tracker and possibly already fixed.


----------



## rigoletto@ (Nov 8, 2019)

I really advise you to bring this issue to the Python mailing list.


----------



## ralphbsz (Nov 10, 2019)

Nope, not here. It is not a FreeBSD general problem, it is a problem of your installation:
`> cat /tmp/test.py
#!/usr/local/bin/python
print('Hello')
> /usr/bin/time /tmp/test.py
Hello
        0.06 real         0.03 user         0.02 sys`


----------



## Bren (Nov 10, 2019)

I can't replicate this issue with a simple script either. Looks like it might be an Ansible issue or one that Ansible uncovers anyway. It happens on four separate servers with different hardware so it's not one particular installation. I can live with it as long as I'm not using FreeBSD as the Ansible master. Maybe if I get some spare cycles I will dig into this more.


----------



## shkhln (Nov 29, 2019)

[ports] Revision 518640
					






					svnweb.freebsd.org
				



That might be relevant.


----------



## Bren (Dec 3, 2019)

shkhln said:


> That might be relevant.



Awesome - it definitely was relevant. Thanks for the pointer. Loading the fdescfs () module and mounting the fs speeds up Ansible operations _substantially._

For future seekers, this is what I had to do:


```
echo 'fdescfs_load="YES"' >> /boot/loader.conf

kldload fdescfs

echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab

mount /dev/fd
```

This reduces the time fact gathering alone takes from 18.5 seconds to 2.8 seconds on one of my systems.


----------



## gschadow (Nov 25, 2020)

I am confirming that there is a bad problem with Python performance. My system is 12.2-RELEASE, Python from pkg install. And application is the AWS CLI suite, like for example 

    aws ec2 describe-instances

it can be extremely slow.


----------



## a6h (Nov 25, 2020)

gschadow said:


> I am confirming that there is a bad problem with Python performance. My system is 12.2-RELEASE, Python from pkg install. And application is the AWS CLI suite, like for example [...] aws ec2 describe-instances [...] it can be extremely slow.


PR 242274 was reported on 2019-11-27. After that there was Revision 518640 to lang/python{27,35,36,37,38} on 2019-11-29 (about one years ago). Obviously your problem is not related to the OP question. You have to send an email to the freebsd-python mailing list. Which version of python, and what's the output of the `uname -a`. Program performance is a quantitative measurement. Bad compare to what? Did you run a benchmark? You have to be more specific about the issue. If it's a standalone problem, maybe you should use high performance alternatives such as array from Numpy package, instead of using python build-in data structures, e.g. list, tuple, etc. Python Lists vs. Numpy Arrays | UCF.edu


----------



## gschadow (Nov 25, 2020)

On FreeBSD 12.2-RELEASE where I am, the fdesc is loaded by default and I have it on, and still Python (3.7) used for AWS CLI is terribly slow.

Bad compared to the Amazon Linux. I migrated a system from Linux to FreeBSD, and what took less than a seconds now takes 10s of seconds and plenty of CPU.


----------

