当前位置:网站首页>网页加载时waiting(TTFB)时间过长的问题解决
网页加载时waiting(TTFB)时间过长的问题解决
2022-06-21 12:13:00 【sunonzj】
博客文章之前是根据id查询的,每次点文章页面都要加载10几秒。
代码没发现有啥问题,就简单的查询也不应该有问题吧。
经过一系列的网页优化+静态化页面后,确实快了,但是之前的方法也保留了。今天通过其它地方的文章外链访问一篇文章的时候等了16秒左右... 简直了,不能甩锅给服务器配置了,带宽够得啊。正好得空,就经过一番查找然后解决了。
解决办法:
将项目数据库配置文件中数据库的链接地址修改为127.0.0.1
之前写的是直接用服务器本机ip连接的...
因为本地连的远程库得写ip,部署一直没有改过。
测试了下:
用服务器ip连接数据库
Waiting为15s左右
用localhost连接
Waiting为1.5s左右
用127.0.0.1连接
Waiting为550ms左右
快了很多啊,不止查文章,后台我的一些功能用起来也快了好多啊。
那么为什么修改数据库链接为127.0.0.1 速度就会提升这么大呢?
mysql的配置问题。
由于MYSQL的安全策略的问题,对于每一个连接以及每一个操作,MYSQL都会check当前用户的主机名,so,当我们对数据库进行op的时候,MYSQL数据库服务器都会check一次主机名,这就导致了我们远端操作数据库的客户端出现几秒钟的等待状态,想要取消MYSQL数据库服务器的这种检查机制,就需要修改MYSQL配置文件
解决办法: 在my.cnf文件的[mysqld]后面添加: skip-name-resolve
扩展:localhost和127.0.0.1
127.0.0.1无需解析,localhost还要本地DNS解析,所有127.0.0.1会更快
一、localhost和127.0.0.1的关系:
localhost也叫local ,正确的解释是:本地服务器。
127.0.0.1在Windows等系统的正确解释是:本机地址(本机服务器或回送地址)。
TA们的解析都是通过本机的hosts文件来引导,之后Windows自动将localhost解析为127.0.0.1 。
二、localhost和127.0.0.1的区别
localhot(local)是不经网卡传输!这点很重要,它不受网络防火墙和网卡相关的的限制。
127.0.0.1是通过网卡传输,依赖网卡,并受到网络防火墙和网卡相关的限制。
一般设置程序时本地服务用localhost是最好的,localhost不会解析成IP,也不会占用网卡、网络资源。
有时候用localhost可以,但用127.0.0.1就不可以的情况就是在于此。猜想localhost访问时,系统带的本机当前用户的权限去访问,而用IP(127.0.0.1)的时候,等于本机是通过网络再去访问本机,可能涉及到网络用户的权限。 本机IP则指你连到网络上的IP地址,可以是内网地址,当然也可能是公网IP,这个就是你实际利用TCP/IP协议与网上计算机通信时使用的IP了。 host文件位置: 修改host文件c://Windows/System32/drivers/etc/hosts
边栏推荐
- [100 unity practical skills] | make the skills or equipment follow the character and rotate continuously in the game
- Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway
- 理解RESTful架构
- Why are there only 13 root domain name servers in the world
- [100 unity pit knowledge points] | unity uses quaternion Angleaxis random one direction
- 2. 引用
- 一篇文章带你搞懂什么是DevOps?
- Redis里5种基本数据类型常用指令
- i. MX - rt1052 clock and phase locked loop (PLL) analysis
- Understand restful architecture
猜你喜欢

异质化社群量化研究4丨RATE OF CHANGE WITH BANDS

创建型模式 - 单例模式

RPC (remote procedure call protocol)

Huawei cloud releases desktop ide codearts

i. MX - rt1052 clock and phase locked loop (PLL) analysis

Standing at the digital tuyere, how can tooling enterprises "fly"

Snow Ice City (blackened)

五大(七大)原则-系统学习三

浅论OCA\UV-OCA LOCA\SLOCA 四种全贴合工艺

DVWA配置教程
随机推荐
typescript localStorage 封装
Centos7 升级MySQL5.6.40至企业版5.6.49
华为是如何从0到1打造以项目为中心运作的项目管理体系的?
SSD的anchor_box计算
Redis个人总结简洁版
Redis personal summary concise version
EasyUI-input取/赋值
在数字时代实现IT敏捷性的12个技巧
i.MX - RT1052 SDCard操作(SDIO接口)
程序三大结构-系统学习一
i. MX - rt1052 boot start
6. 函数
i. MX - rt1052 SPI and I2C interfaces
MySQL 5.6.49 enterprise version setting password complexity policy
Standing at the digital tuyere, how can tooling enterprises "fly"
STM32笔记之 PWM(脉宽调制)
UML的六种关系-系统学习四
5. 数组
Schéma technique du système de surveillance de l'environnement de la salle de distribution
Ansible operating instructions for configuring SSH authentication free for the first time