1. 知乎有时候打开一个链接非常之慢,大量评论展开更是无法忍受。有时页面刷新完了,点任何连接都没有响应。
2. 豆瓣经常挂掉,502 之类的(当然我知道这个跟 python 无关),也存在同样的问题,时不时会响应非常慢,一个页面等待 10s 以上。
3. v2ex 相比来说要小一点儿,也是类似的问题,但它时快时慢跟网络环境关系差别巨大。
======================================
天天刷网页,这三个网站卡顿是很明显的现象。
如果没遇到这个问题请不要捣乱。
而且我没有推导出跟语言『有关』,我在询问『是否有关』。
A、B、C 使用了同一种技术,有同样的症状,难道不能怀疑这种技术 普遍/很可能 存在这样的症状么?
为什么当年 twitter 从 ruby 迁移到了 java ?
回复内容:
再补一刀吧,之前没看到。虽然我用豆瓣从没碰到过 502
但是,如果你真的碰到了,而且确信这个 502 来自豆瓣的前端 HTTP 服务器
那么这是唯一一个 可能和后面 Python 有关的现象。
------------
一个网站是不是卡顿,可能的情况太多,随之带来的细节表现不同都是可以值得分析的问题。
- 线路
- DNS
- CDN / 文件服务
- 静态资源
- 动态资源
- 缓存同步
国内出名的南北分裂、电联分裂。虽然这些年很少再听到集中讨论这个问题,但真碰到谁家没做好双线机房设置也只能自认倒霉是不?去 ping 一下网站域名,看看 ping 的延迟,如果异乎寻常的大(比如数百毫秒到 1 秒以上,多半是这里的问题)。
DNS
其实和线路一样相关。好的 DNS(e-DNS 扩展)会根据用户当前位置,为用户分配合适的服务器。当然如果不支持 e-DNS 是没办法的,服务器只有一个 IP 也没什么可以做的。
CDN / 文件服务
CDN 是将一时不会改变的静态内容发放给用户的最重要渠道。文件服务(Amazon S3 等)通常与 CDN 做类似的事情 / 与 CDN 搭配使用。CDN 通过动态缓存静态文件到所谓的 edge server - 通常是位于靠近 ISP 接入的机房,使用户访问这些资源的路径更短、延迟更低。同时因为 CDN 的巨大主机数量,正确使用也可以降低网站本身服务器压力。知乎的图片来自 http://p4.zhimg.com 等一系列域名,这些域名实际上是重定向到云存储 / CDN 的主机去,譬如知乎:
$ nslookup p3.zhimg.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
p3.zhimg.com canonical name = d.qiniudn.com.
d.qiniudn.com canonical name = wsall.36tr.com.wscdns.com.
wsall.36tr.com.wscdns.com canonical name = 08911.xdwscache.glb0.lxdns.com.
Name: 08911.xdwscache.glb0.lxdns.com
Address: 122.228.218.146
1、简短回答:不是Python导致的,我这里豆瓣非常快,但知乎好像真的有点卡顿的现象(也有可能看到问题之后才脑补意识到的.......).
2、为什么不是Python导致的
或者说,任何一个网站很卡,都不大应该说是其后端的某个语言导致的(虽然写的很烂确实会导致卡顿,但知乎之类的肯定不是这个原因),对于知乎这类访问量很大,同时又大量文本内容的网站,会大量使用Cache,也就是说直接从内存取数据不再频繁访问数据库,从这个层面基本各个语言都不会差太多,甚至HTML页面也都是cache出来的.
3、是什么导致了卡顿
很有可能是大量的Ajax请求导致的,我注意到鼠标移动到人名、话题上的时候都会触发3个新的Ajax请求,新进入一个页面大约有30~40个HTTP请求发出去,虽然数据量不大,但如果浏览器性能较差或者系统分配给浏览器的内存不足,频繁的调用Ajax可能就会需要等待其他地方释放一点内存。
我没有仔细看,但似乎有些知乎的页面是整个HTML页面都是Ajax异步渲染的,由于dom树的构造也很耗费性能,所以如果机器过老,或者网络太差都会出现这个问题.
4、如何解决
其实我并没有特别留意到楼主说的卡顿现象,解决方法可能就是升级机器吧......对于知乎来说,可能需要考虑部分网络不好的用户,尽量少的发送HTTP请求,一个页面30多个请求我感觉还是蛮多的.
或者学习Quora进行延迟加载(直观的猜测),就是不要进入页面的时候把Ajax请求一口气全发出去,而是先等用户进入页面(比如8个请求的时候),然后页面基本信息渲染完毕后再依次发送其他Ajax请求。 终于明白为什么上不了YouTube了 我还想补充一下,php也是垃圾啊,facebook那么大的网站,用php做的,根本上不去嘛。 知乎一直时好时坏,有时翻墙才能上。和Python无关吧,也许是被攻击了呢。 武功差不要怪手上的兵器,
网站慢不要怪所用的语言。 我感觉google也做的挺烂的,以前偶尔能上去,现在完全上不去了。 "屙屎不出赖地硬" 怪毛线语言,都是习惯问题。 首先,说Python慢,这是和编译语言比,比如与C,C++,Java比,在动态语言中,它并不慢,它比Ruby要快,它和Perl性能相当。如果选择动态语言的话,Python并不是很慢。另一方面,如果做网站开发,语言的不是速度的瓶颈,比如现在用Python写的程序全部用C写,程序当然会快一点,但是改变不是很大。Web网站一般会有很多对IO的操作,比如对数据库的访问,对硬盘的访问响应用户的请求,80%,90%你的时间都花在IO上,语言的速度,相对而言,不是那么重要。也可以这样说,网站的性能主要取决于架构设计的是否合理。因为网站需要响应大量的并发的请求,如果你的设计的不好,即使你用C写的,也可能无法应付。所以更多的考虑是在架构设计上,要使架构体系不会产生速度瓶颈。

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.

Python's real-world applications include data analytics, web development, artificial intelligence and automation. 1) In data analysis, Python uses Pandas and Matplotlib to process and visualize data. 2) In web development, Django and Flask frameworks simplify the creation of web applications. 3) In the field of artificial intelligence, TensorFlow and PyTorch are used to build and train models. 4) In terms of automation, Python scripts can be used for tasks such as copying files.

Python is widely used in data science, web development and automation scripting fields. 1) In data science, Python simplifies data processing and analysis through libraries such as NumPy and Pandas. 2) In web development, the Django and Flask frameworks enable developers to quickly build applications. 3) In automated scripts, Python's simplicity and standard library make it ideal.

Python's flexibility is reflected in multi-paradigm support and dynamic type systems, while ease of use comes from a simple syntax and rich standard library. 1. Flexibility: Supports object-oriented, functional and procedural programming, and dynamic type systems improve development efficiency. 2. Ease of use: The grammar is close to natural language, the standard library covers a wide range of functions, and simplifies the development process.

Python is highly favored for its simplicity and power, suitable for all needs from beginners to advanced developers. Its versatility is reflected in: 1) Easy to learn and use, simple syntax; 2) Rich libraries and frameworks, such as NumPy, Pandas, etc.; 3) Cross-platform support, which can be run on a variety of operating systems; 4) Suitable for scripting and automation tasks to improve work efficiency.

Yes, learn Python in two hours a day. 1. Develop a reasonable study plan, 2. Select the right learning resources, 3. Consolidate the knowledge learned through practice. These steps can help you master Python in a short time.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor