为什么Google Appengine连接到CloudSQL的速度很慢? [英] Why is Google Appengine so slow connecting to CloudSQL

查看:168
本文介绍了为什么Google Appengine连接到CloudSQL的速度很慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在连接到CloudSQL后端时,我发现开发和生产之间的延迟差异非常大,远远超出我的预期。






  1. 我获取了125,250,500,1000和2000行(行大小约30字节)
  2. 我提取了每行大小20次,以获得时间的良好抽样

测试在三种环境中运行: / p>
$ b


  1. 托管的appengine

  2. 本地开发模式,但通过静态IP连接到CloudSQL
  3. 在本地开发模式并连接到运行MySQL的本地VM

在这里你可以看到结果:



现在我期望一些速度波动大约为50ms-200ms,但3-4秒的时间似乎有点高。



我是appengine的新手,所以任何新的错误,这一点不会造成这种情况吗?还是其他建议?我在appengine上的代码中运行了一个profiler,并且调用了_apiProxy.Eventwait,它至少消耗了500毫秒,但没有超过750毫秒,除此之外,还有长时间运行的调用。一些较短的正在运行的调用当然会加起来,但它不像我有一个需要调整的循环或任何东西。



预先感谢!

解决方案

首先,检查您使用的连接路径:您是通过最新的记录方法进行连接?云端SQL以前的连接路径较慢,现在已被弃用,但仍然可以正常工作,因此您可以通过它访问。

第二,App Engine应用程序和云SQL实例在同一位置?请检查您的Cloud SQL设置中的首选位置是否设置为遵循所连接的应用引擎应用。



作为最后一种可能性,你有本地连接的数据,确保你正在重用数据库连接,使新的连接可能很昂贵。如果出于某种原因,您的应用在本地重新使用连接,但在App Engine侧创建新连接,则可能会导致此行为。但正如我所说,这似乎不太可能。


I am seeing a drastic difference in latency between development and production when connecting to a CloudSQL backend, much more so than I would expect.

I ran a test where:

  1. I fetched 125, 250, 500, 1000 and 2000 rows (row size approximately 30bytes)
  2. I fetched each row size 20 times, to get a good sampling of the time

The test was run in three environments:

  1. Hosted appengine
  2. Development mode locally, but connecting to CloudSQL via static IP
  3. Development mode locally and connecting to a local VM running MySQL

Here you can see the results:

Now I would expect some speed fluctuations on the order of 50ms-200ms but 3-4 seconds seems a bit high.

I'm new to appengine, so any newb mistakes that might be causing this? Or other suggestions? I ran a profiler on my code in appengine and there is a call to _apiProxy.Event "wait" that eats up at least 500ms, but didn't go up more than 750ms, other than that, there was any long running calls. A number of shorter running calls that eventually add up of course, but it's not like I have a loop that needs to be tuned or anything.

Thanks in advance!

解决方案

First off, check the connectivity path you are using: are you connecting via the latest documented method? Cloud SQL used to have a connectivity path which is slower and is now deprecated, but still functioning, so you could be accessing via that.

Second, is the App Engine app and Cloud SQL instance in the same location? Check that the "Preferred Location" in your Cloud SQL settings are set to follow the app engine app you are connecting to.

As a last possibility, which seems unlikely given that you have data connecting locally, make sure you are reusing database connections, making new ones can be expensive. If there was some reason why your app is reusing connections locally but making new ones on the App Engine side, that could create this behavior. But like I said, this one seems unlikely.

这篇关于为什么Google Appengine连接到CloudSQL的速度很慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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