本地和远程服务器上的高网络TTFB时间 [英] High network TTFB times on local and remote server

查看:204
本文介绍了本地和远程服务器上的高网络TTFB时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解决一些针对Angular 1.3,NodeJS,Postgres DB应用程序堆栈的http调用速度缓慢的问题。远程托管在AWS EC2实例上。





解释所查询的结果

 计划时间: 0.915 ms 
执行时间:1.687 ms
(30行)






版本:



Postgres :9.6.1

 选择版本(); 

x86_64-apple-darwin14.5.0上的PostgreSQL 9.6.1,由Apple LLVM 7.0.2版(clang-700.1.81)编译,64位

节点:7.4.0



Knex :0.12.6



角度:1.3

解决方案


比较本地和远程AWS响应时间会产生类似的缓慢情况。


此指出问题最可能的原因-数据库连接使用效率低。



TTFB不一致的原因是,有时您的请求会到达,而所有可用的连接都会被消耗,没有按时发布。在这种情况下,默认的 pg 驱动程序会导致等待一段时间,直到池中的连接可用为止。



为此,您需要研究如何使用连接:




  • 池的大小

  • 在所有请求中管理连接的方式


I am addressing slowness in a few http calls for an Angular 1.3, NodeJS, Postgres DB app stack. Remote is hosted on AWS EC2 instances.

Google's dev tools documentation gave me some good understanding of the timings, and this SO post explains things you can do about it.

My network response for a particular HTTP call shows slowness in TTFB (time-to-first-byte), sometimes as slow as 3s added in the ttfb timing, indicating either:

a) A bad network connection between the client and server. So data is slow to reach the server and get back.

b) A slow server processing the request. This is either because the hardware is weak or the application running is slow. Or, both of these problems can exist at once.

What I've tried:

  • Comparing local and remote AWS response timings yield similar slowness. So it doesn't appear the networks between my client and my server are the problem
  • Running EXPLAIN ANALYZE on the queries in question yield fast processing time < 2ms
  • We use Redis caching for other parts of the server, but not this particular call

My question is: If it doesn't appear there's much difference in speed between remote and local, and the query times are fairly quick, what else could be adding slowness? Is there some middleware or processing on the Node side, or some throttling going on from Angular?

Curiously, what I've also found is the TTFB timing occassionally varies wildly for the same request... with TTFB time < 500ms, and other times TTFB > 3s. Why is this?

Network response:

EXPLAIN ANALYZE results of the queries in question:

 Planning time: 0.915 ms
 Execution time: 1.687 ms
(30 rows)


Versions:

Postgres: 9.6.1

select version();

 PostgreSQL 9.6.1 on x86_64-apple-darwin14.5.0, compiled by Apple LLVM version 7.0.2 (clang-700.1.81), 64-bit

Node: 7.4.0

Knex: 0.12.6

Angular: 1.3

解决方案

Comparing local and remote AWS response timings yield similar slowness.

This points to the most likely cause of the problem - inefficient use of database connections.

The inconsistent TTFB comes from the fact that sometimes your request arrives while all available connections are consumed and not released on time. The default pg driver in this case causes a wait period till a connection becomes available in the pool.

To solve this, you need to look into how you use the connections:

  • the size of the pool
  • the way connections are managed in all requests

这篇关于本地和远程服务器上的高网络TTFB时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆