三个基于 Python 的网站:知乎、豆瓣、V2EX 都存在卡顿的问题,是 Python 的问题吗?
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
不是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写的,也可能无法应付。所以更多的考虑是在架构设计上,要使架构体系不会产生速度瓶颈。

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Golang is more suitable for high concurrency tasks, while Python has more advantages in flexibility. 1.Golang efficiently handles concurrency through goroutine and channel. 2. Python relies on threading and asyncio, which is affected by GIL, but provides multiple concurrency methods. The choice should be based on specific needs.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.
