Pyramid server on vmware responds very slowly - python

First of all I'm new to Python and Pyramid framework.
I have:
Win7 on my host
Debian 6 on my vmware guest
Python 2.6 on Debian machine
Pyramid 1.3 on Debian machine
I created a virual environment using 'virualenvwrapper' and now I'm running 'Hello world' example from here http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/firstapp.html#firstapp-chapter
The problem is that when I request http://localhost:8080/hello/world in Debian machine everything works fine. But when I request http://192.168.25.129:8080/hello/world from my host Win7 machine it takes 5-7 seconds to get response from server (192.168.25.129 thi is an vmware ip adress connected via NAT). I can not find the reason why it takes so much time.
I also installed 'apache2' on Debian machine to test request speed and found that apache respond takes 1 sec maximum. So is it a problem of Python or Pyramid?
How can I reduce respond time of Pyramid server?
PS:sorry for bad english :)

As far as I know, Pyramid itself provides only debugging web server. It really very slow. For production you can use 'waitress' web server. It is much more faster.

This problem probably has very little to do with python or pyramid and much more to do with the configuration of your virtual machine. If you really want to see what pyramid is doing you can turn on the performance profiler in the debug toolbar and find out where in the request things are taking a long time. If there is nothing slow in the pyramid side of the request, then you know it's before/after and you can look at the system setup, wsgi server and middleware.

Related

gRPC becomes very slow all of a sudden

I use gRPC for Python RPC on the same machine. It has been working great till yesterday. Then, all of a sudden, it started being very slow. The helloworld example now takes about 78s to complete. I tested it on three computers on the same network, all Ubuntu 18.04, with the same results. At home, the same example runs almost instantaneously. I suspect some networking issue, maybe an automatic update on the gateway, but I'm at a loss on how to troubleshoot the problem. Any suggestions?
EDIT:
I still don't know what happened, but I found a workaround. Replacing localhost with 127.0.0.1 in the grpc.insecure_channel connection string makes gRPC responsive again.

Slow response from IIS server for my python flask application

I have created a web application in python using the Flask framework. I have hosted this python application in IIS on windows server2012.
when I called this application with URL https://localhost/ on the server machine, I am getting a quick response(less than a second). But when I tried to call the same application from another machine inside the corporate network, it is taking more than 2mins time to get the response. I am calling the web application through the IP address of the server machine i.e XX.XXX.XX.XXX:80.
could anyone answer why is it taking too much time and how to get rid of this latency time?
I have used below resources to create the web application and opening the inbound port.
python deployment:
https://medium.com/#bilalbayasut/deploying-python-web-app-flask-in-windows-server-iis-using-fastcgi-6c1873ae0ad8
Inbound port opening:
https://manage.accuwebhosting.com/knowledgebase/2886/How-to-configure-IIS-to-access-website-using-IP-address.html
Regards,
Naresh.
My problem has been solved, i have tried with host name instead of IP address. It is so fast.
Regards,
Naresh.

Django tutorial: problems accessing development server

I am going through the Django tutorial and am running into problems when trying to view my webpage. I am at the very beginning of the tutorial when I first run the command python manage.py runserver xxx.xxx.xxx.xxx:8000 (replace the x's with my remote server's IP). When I try to navigate to http://xxx.xxx.xxx.xxx:8000 on my local machine, Chrome gives me the error ERR_CONNECTION_REFUSED. I have also tried running the server on 0.0.0.0:8000 and the same issue persists. The port is definitely open and there are no firewalls blocking it - when I plug in my IP and 8000 into this site it claims it is open: http://ping.eu/port-chk/.
I get no error messages on my console from the Django side of things. What could be causing this error? I really don't know much about servers or ports. Thanks in advance.
I am on a virtual Linux server running CentOS 6.4. My local machine is running Mac OS 10.9.5
EDIT:
When I run netstat --listen, port 8000 doesn't show up in the Local Address column, even though my Django dev server claims to be running. Someone mentioned to me that this means my application is not listening on this port. What does this mean and how do I remedy it?
EDIT:
I can access the page through my phone's internet with no issues. What gives?
If you're running Django inside a VM but accessing it from the host Mac, you'll need to forward the port. See the settings in Virtualbox/VMWare/whatever.
Note however that Django runs perfectly well directly on a Mac, so if you're just learning it may be simpler to just install it there.
Don't issue no IP, runserver will tell you where you can connect to when launching it.
Since you're launching it from your VM, you might supply the IP.
Ensure system level routing is okay.
Add your host local IP to the ALLOWED_HOSTS setting.

Host a Python based Websocket server

I am looking to host a basic Websocket server.
The code I want to see running is : FastFlicker
Do you know how and where I can host this application online?
PythonAnywhere dev here. Unfortunate we can't host websocket-based apps on our site right now. The toggle you spotted enables/disables websockets for our in-browser consoles, it's not related to running your own websocket server.
I've added an upvote for websockets to our own issue tracker, but for now you'll have to use a different service :-(
Your solution is OpenShift, even with the free plan you can host FastFlicker.
Click Add Application, choose the good cartridges (Python 2.7).
Then use your gitHub repo url to get the source.
Once the application is running, you need to SSH it to change the address and the port (see this Post).
To be able to ssh you need first to generate a ssh key and to add it in setting on the website
Ok, now kill all processes that uses your port. (lsof -i :8080)
Start your application and now it's working!
(It is in app-deployments/current/repo/ for me, then python FastFlicker.py &)
It is currently hosted here : ws://main-fastflicker.rhcloud.com:8000/
And to test it, you know you can use this generic client..

How to make Django's devserver public ? Is it generally possible?

I'm currently trying out the Django framework and I would share/present/show some stuff I've made to my workmate/friends. I work in Ubuntu under Win7 via VMware. So my wish/desire is to send my current pub-IP with port (e.g http://123.123.123.123:8181/django-app/) to my friends so they could test it.
the Problem is - I use django's Dev server (python /path-to-django-app/manage.py runserver $IP:$PORT).
How do I make the devserver public?
EDIT:
Oh, there's something I forgot to mention. As I sad I use VMware with Ubuntu. I have a shellscript that returns me my current int-IP 192.168.xx.xx and saves it in a environment-variable ($CUR_IP)
So, each time I want to run django's devserver I simply execute
python /path-to-django-site/manage.py runserver $CUR_IP:8080
At this way I become an http-adress (e.g.http://192.168.40.145:8080/app-name/) which I CAN USE OUTSIDE my virtual machine. I could test it on my host (win7) machine. That's actually the reason why I asked the question. I thought there's a way to use the ext-IP and make runserver usable outside too
python manage.py runserver 0.0.0.0:8181
This will run development server that should listen on all IP's on port 8181.
Note that as of Jun 17, 2011 Django development server is threaded by default (ticket #1609).
From docs:
Note that the default IP address,
127.0.0.1, is not accessible from other machines on your network. To
make your development server viewable
to other machines on the network, use
its own IP address (e.g. 192.168.2.1)
or 0.0.0.0.
Assuming you have ruby installed, you just have to get localtunnel:
gem install localtunnel
then start your python development server with:
python manage.py runserver 0.0.0.0:8000
in another shell, start localtunnel:
localtunnel -k ~/.ssh/id_rsa.pub 8000
That will output an url to access your local server.
Port 8000 is now publicly accessible from http://xxxx.localtunnel.com
That's it.
192.168.*.* is a LAN-private address -- once you've done the proper VMWare (or other VM manager) and firewall incantations to make it accessible from the LAN, it still won't be accessible from outside the LAN, i.e., from the internet at large (a good thing too, because such development servers are not designed for security and scalability).
To make some port of a machine with a LAN-private IP visible to the internet at large, you need a router with a "virtual servers" ability (many routers, even cheap ones, offer it, but it's impossible to be specific about enabling it since each brand has its own idiosyncratic way). I would also recommend dyndns or other similar service to associate a stable DNS name to your always-varying public IP (unless you're splurging for a static IP from your connectivity provider, of course, but the latter option is becoming costlier all the time).
superuser.com or serverfault.com may provide better answers and details (once you give every single little detail of your configuration in a question) since the question has nothing much to do with software development and everything to do with server administration and configuration.
I had to add this line to settings.py in order to make it work (otherwise it shows an error when accessed from another computer)
ALLOWED_HOSTS = ['*']
then ran the server with:
python manage.py runserver 0.0.0.0:9595
Also, make sure that your firewall allows communication to the chosen port (9595 in this case)
Already answered but adding npm alternate of same localtunnel
sudo npm install -g localtunnel
lt --port 8000 --subdomain yash
If you are using Virtualbox, You need to change the network setting in VB from "NAT" to "Bridged Adaptor". Then restart the linux. Now if you run sudo ifconfig you are able to see your IP address like 192.168.*.* . The last step is runserver
python manage.py runserver 192.168.*.*:8000
Cheers!
You need to configure bridged networking in VMWare and also grant access to the target port in Ubuntu firewall.
Alternatively, you can use cotunnel, Just run cotunnel in your ubuntu (in VMware) change your tunnel port in cotunnel dashboard which port you are using in local side. It gives public url and you can share the url with your friends.
Your Django server can listen to 127.0.0.1 or 0.0.0.0 (I prefer 0.0.0.0) it does not matter for cotunnel.
Might I suggest trying something like pyngrok to programmatically manage an ngrok tunnel for you? Full disclosure, I am the developer of it. Django example here, but it's as easy as installing pyngrok:
pip install pyngrok
and using it:
from pyngrok import ngrok
# <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:8000">
http_url = ngrok.connect(8000)
No messing with ports or firewalls or IP addresses, and now you can also inspect the traffic (which is useful since what you're doing here is ongoing development, not running a prod-ready server).

Categories