我有一个相当简单的 Google Apps 脚本 Web 应用程序,它使用 JDBCGoogleCloud 连接来连接到 Google 云 mySQL 数据库。该系统允许会议中的用户进行投票、标记其出席情况以及表明他们想要发言等操作。它作为嵌入的网络小程序在 Google 网站上运行。
只有十几张表,最大的表也就200行6列左右。数据主要是 varchar、时间戳和一些tinyint。
这工作正常,但性能差异很大。我可以连续运行相同的“SELECT * FROM TABLENAME”查询 10 次,每次返回数据的时间从大约 1 秒到最多 70 秒不等。
对于这是为什么有什么想法吗?这使得系统变得难以依赖。
我还尝试使用普通的 JDBC.getConnection 并将其指向内部的实验室 mySQL 服务器。我看到同样的行为。有时它会在一两秒内执行,有时则需要几十秒。 如果我将代码指向 Google 表格而不是从表格中查询,它的速度始终会快得多(几分之一秒)。然而,这在写入纸张时会带来其他问题。
我想我可以尝试为 Google Apps 脚本寻找一个与 mySQL 交互的第三方插件,看看它是否有同样的问题,或者是否与 Google 的实现有关。
但我真的只是想看看其他人是否也遇到类似的问题?
代码示例:
var myDBInfo = getDBSettings()
var conn = Jdbc.getCloudSqlConnection(myDBInfo.ConnString,myDBInfo.DBUser, myDBInfo.DBPassword)
var stmt = conn.createStatement()
var query = "SELECT * from Attendance"
rs = stmt.executeQuery(query)
//Get columns
var meta=rs.getMetaData();
var cols=meta.getColumnCount();
var info=[];
for( var i =1; i <= cols; i ++ )
{
info[i] = { label:meta.getColumnLabel(i), type:meta.getColumnTypeName(i) }
}
//get data
var ret = [];
while( rs.next())
{
var row = {};
for( var i=1; i <= cols; i ++ )
{
row[info[i].label] = rs.getString(i)
}
ret.push( row );
}
rs.close()
stmt.close()
conn.close()
我对“next()..方法”有同样的问题。
我的日志:
19:23:47 : SELECT `history_id` FROM `call_history` WHERE `context_start_time` BETWEEN '1710173130' AND '1714382429' LIMIT 200
19:24:36 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:928:5)] close 0
19:24:36 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:933:3)] Time for 'queryMySqlTableAsObject': 48820
19:24:36 Items found: 200
19:24:36 : SELECT `history_id` FROM `call_history` WHERE `context_start_time` BETWEEN '1710173130' AND '1714382429' LIMIT 200
19:25:24 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:928:5)] close 0
19:25:24 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:933:3)] Time for 'queryMySqlTableAsObject': 47989
19:25:24 Items found: 200
19:25:24 : SELECT `history_id` FROM `call_history` WHERE `context_start_time` BETWEEN '1710173130' AND '1714382429' LIMIT 200
19:26:13 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:928:5)] close 0
19:26:13 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:933:3)] Time for 'queryMySqlTableAsObject': 49332
19:26:13 Items found: 200
19:26:13 : SELECT `history_id` FROM `call_history` WHERE `context_start_time` BETWEEN '1710173130' AND '1714382429' LIMIT 200
19:27:01 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:928:5)] close 0
19:27:01 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:933:3)] Time for 'queryMySqlTableAsObject': 47899
19:27:01 Items found: 200
19:27:01 : SELECT `history_id` FROM `call_history` WHERE `context_start_time` BETWEEN '1710173130' AND '1714382429' LIMIT 200
19:27:50 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:928:5)] close 0
19:27:51 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:933:3)] Time for 'queryMySqlTableAsObject': 48708
19:27:51 Items found: 200
19:27:51 // Total time for 5 iterations: 243730 milliseconds Average time per iteration: 48746 milliseconds
19:27:51 : SELECT `history_id` FROM `call_history` WHERE `context_start_time` BETWEEN '1710173130' AND '1714382429' LIMIT 200
19:28:39 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:928:5)] close 0
19:28:39 [DEBUG MSG at queryMySqlTableAsObject (Jdbc:933:3)] Time for 'queryMySqlTableAsObject': 48465
19:28:39 Items found: 200
19:28:39 // Single callable: 48474 milliseconds
如果没有收到数据直接发送查询,一次调用大约需要5秒。