主流的web server 一个巴掌就能数出来,apache,lighttpd,nginx,iis
application,中文名叫做应用服务,就是你基于某个web framework写的应用代码DB server 泛指存储服务,web开发中用mysql比较多,最近几年因为网站规模扩大,memcache,redis这种key-value等存储也流行开来
放在最前面的 web server 有3个功能
高效率处理静态文件 ,web server都是用c开发,调用是native的函数,对IO,文件传输都做针对性的优化
充当一个简易的网络防火墙 ,可以denny一些ip,简单的控制并发连接数量等等,聊胜于无
处理高并发短连接请求 ,把成千上万用户的request 通过内网的几十个长连接进行转发,原因一个是web server处理高并发很专业,另外一个原因是大部分的application所用的框架都不具备处理高并发的能力
实际上,市面上有部分web framework由于内置了支持epoll/kqueue 等高效网络库,而具备了处理高并发的能力,比如说 python的tornado,java系的tomcat,jetty等等,有人就去掉前端的web server,直接裸奔,但是在部署公网应用时候,最好别这样做,因为前面提到的1,2两个原因,用户brower到web server的网络状况是千奇百怪,你无法想象的,
web server 强烈建议使用nginx,原因有三
性能非常卓越,非常稳定
安装简单,依赖包少
conf文件非常容易配置,比apache/lighttpd都要简单
部署python开发的web程序有9种方法
mod_python ,这是apache内置的模块,很严重的依赖于mod_python编译使用的python版本,和apache配套使用,不推荐
cgi ,这个太old,不推荐,而且nginx不支持cgi方式,只能用lighttpd或者apache
fastcgi ,这个是目前流行最广的做法,通过flup模块来支持的,在nginx里对应的配置指令是 fastcgi_pass
spawn-fcgi ,这个是fastcgi多进程管理程序,lighttpd安装包附带的,和 flup效果一样,区别是flup是 python代码级引入,spawn-fcgi是外部程序。spawn-fcgi用途很广,可以支持任意语言开发的代码,php,python,perl,只要你代码实现了fastcgi接口,它都可以帮你管理你的进程
scgi ,全名是Simple Common Gateway Interface,也是cgi的替代版本, scgi协议 很简单,我觉得和fastcgi差不多,只是没有怎么推广开来,nginx对应的配置指令是scgi_pass,你想用就用,flup也支持。
http ,nginx使用proxy_pass转发,这个要求后端appplication必须内置一个能处理高并发的http server,在python的web框架当中,只能选择tornado.
python程序员喜欢发明轮子,tornado除了是一个web framework之外,它还可以单独提供高性能http server,所以,如果你采用其他python框架写代码,比如说bottle,也一样可以通过import tornado 来启动一个高性能的http server,同样的可以采用http协议和nginx一起来部署。扩展开来,python包里面能处理高并发的http server还有很多,比如说gevent,也可以被其他框架引用来支持http方式部署。
现实当中,用java来做web程序,通常就用http和nginx配合,应用服务器选择tomcat或者jetty
uwsgi ,包括4部分组成,
uwsgi协议
web server内置支持协议模块
application服务器协议支持模块
进程控制程序
nginx从0.8.4开始内置支持uwsgi协议,uwsgi协议非常简单,一个4个字节header+一个body,body可以是很多协议的包,比如说http,cgi等(通过header里面字段标示),我曾经做个一个小规模的性能对比测试,结果表明,uwsgi和fastcgi相比,性能没有太明显的优势,也可能是数据集较小的原因
uwsgi的特点在于自带的进程控制程序.它是用c语言编写,使用natvie函数,其实和spawn-fcgi/php-fpm类似。所以uwsgi可以支持多种应用框架,包括(python,lua,ruby,erlang,go)等等
Gunicorn ,和uwsgi类似的工具,从rails的部署工具(Unicorn)移植过来的。但是它使用的协议是 WSGI,全称是Python Web Server Gateway Interface ,这是python2.5时定义的官方标准( PEP 333 ),根红苗正,而且部署比较简单, http://gunicorn.org/ 上有详细教程
mod_wsgi ,apache的一个module,也是支持WSGI协议, https://code.google.com/p/modwsgi/
fastcgi协议和http协议在代码部署中的的优劣对比
fastcgi虽然是二进制协议,相对于http协议,并不节省资源。二进制协议,只能节省数字的表达,比如 1234567,用字符串表示需要7个Byte,用数字就是4个Byte,而字符串到哪里都一样
fastcgi在传输数据的时候,为了兼容cgi协议,还要带上一堆cgi的环境变量,所以和http协议相比,用fastcgi传输数据并不省,反而多一些
fastcgi 唯一的优点是,它是长连接的,用户并发1000个request,fastcgi可能就用10个 链接转发给后端的appplication,如果用http协议,那来多少给多少,会向后端appplication 发起1000个请求
http代理转发方式,在面对超高并发的情况下会出问题,因为, tcp协议栈当中,port是int16整型 你本地新建一个connect,需要消耗一个端口,最多能到65536。外部并发几十万个请求,port池耗干,你的服务器只能拒绝响应了
总结
我个人习惯是用 fastcgi 协议部署python程序,简单省事,选择技术方案,一定要选择最简单最常见的,本博客的fastcgi运行脚本如下
kill - `cat / tmp / django.pid` echo 'restart django....' python . / manage.py runfcgi - - settings = lutaf.settings_r maxchildren = maxspare = minspare = method = prefork pidfile = / tmp / django.pid host = 127.0 . 0.1 port = outlog = / tmp / dj.out errlog = / tmp / dj.error
推荐大家尝试 Gunicorn ,这是未来发展方向

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python and C have significant differences in memory management and control. 1. Python uses automatic memory management, based on reference counting and garbage collection, simplifying the work of programmers. 2.C requires manual management of memory, providing more control but increasing complexity and error risk. Which language to choose should be based on project requirements and team technology stack.

Python's applications in scientific computing include data analysis, machine learning, numerical simulation and visualization. 1.Numpy provides efficient multi-dimensional arrays and mathematical functions. 2. SciPy extends Numpy functionality and provides optimization and linear algebra tools. 3. Pandas is used for data processing and analysis. 4.Matplotlib is used to generate various graphs and visual results.

Whether to choose Python or C depends on project requirements: 1) Python is suitable for rapid development, data science, and scripting because of its concise syntax and rich libraries; 2) C is suitable for scenarios that require high performance and underlying control, such as system programming and game development, because of its compilation and manual memory management.

Python is widely used in data science and machine learning, mainly relying on its simplicity and a powerful library ecosystem. 1) Pandas is used for data processing and analysis, 2) Numpy provides efficient numerical calculations, and 3) Scikit-learn is used for machine learning model construction and optimization, these libraries make Python an ideal tool for data science and machine learning.

Is it enough to learn Python for two hours a day? It depends on your goals and learning methods. 1) Develop a clear learning plan, 2) Select appropriate learning resources and methods, 3) Practice and review and consolidate hands-on practice and review and consolidate, and you can gradually master the basic knowledge and advanced functions of Python during this period.

Key applications of Python in web development include the use of Django and Flask frameworks, API development, data analysis and visualization, machine learning and AI, and performance optimization. 1. Django and Flask framework: Django is suitable for rapid development of complex applications, and Flask is suitable for small or highly customized projects. 2. API development: Use Flask or DjangoRESTFramework to build RESTfulAPI. 3. Data analysis and visualization: Use Python to process data and display it through the web interface. 4. Machine Learning and AI: Python is used to build intelligent web applications. 5. Performance optimization: optimized through asynchronous programming, caching and code

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)