分析 OnPrem 和 AWS 环境之间 SQL 查询的性能
Analyzing the performance of SQL queries between OnPrem and AWS environment
我正在对现有 REST 服务进行现代化改造,并从 OnPrem 迁移到 AWS。
遗留应用程序
deployed in a OnPrem Liberty Server
MS SQL server DB was used.
Spring/Hibernate was the core technologies.
新申请详情:
Spring Boot deployed in the AWS environment in a docker container
Server-Tomcat embedded with the Spring boot.
Database is the existing MS Sql server and it is located OnPrem
一些之前执行时间不到 500 毫秒的查询现在最多需要 2000 毫秒。查询、逻辑和其他代码相关的东西在旧应用程序和新应用程序之间是相同的。我们无法找到查询为何花费更多时间的原因。
在旧应用程序中,我们使用 server.xml 配置数据源,在新应用程序中,我们在 Spring 中配置数据源] 开机 application.properties 。以下是数据源配置:
Liberty 服务器数据源:
<dataSource id="Microsoft SQL Server JDBC Driver - DataSource - JVM3" jndiName="jdbc/xxx" containerAuthDataRef="yyy" statementCacheSize="50" isolationLevel="TRANSACTION_READ_COMMITTED">
<jdbcDriver libraryRef="MSSQLJDBCLib"/>
<properties.microsoft.sqlserver databaseName="dbName" serverName="servername.com" portNumber="9999" lockTimeout="2000" packetSize="4096" sendStringParametersAsUnicode="false" trustStorePassword="{xor}" beginTranForVendorAPIs="false" freeResourcesOnClose="false" jmsOnePhaseOptimization="false" reauthentication="false" preTestSQLString="SELECT 1" validateNewConnection="false" validateNewConnectionRetryInterval="3" errorDetectionModel="ExceptionMapping" nonTransactionalDataSource="false" name="Microsoft SQL Server JDBC Driver - DataSource - JVM3" enableMultithreadedAccessDetection="false" beginTranForResultSetScrollingAPIs="false" validateNewConnectionRetryCount="100" connectionSharing="1"/>
<connectionManager agedTimeout="-1" connectionTimeout="180" maxIdleTime="300" maxPoolSize="30" minPoolSize="0" reapTime="240" purgePolicy="FailingConnectionOnly"/>
</dataSource>
Spring 引导数据源:
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName
spring.datasource.hikari.maximumPoolSize=30
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=180000
可能影响新旧应用程序之间查询性能的其他参数是什么?
注意:AWS 服务器和 OnPrem 数据库之间的 ping 时间不到 2 毫秒(可以忽略不计)。
问题已解决。我们对数据库所做的所有查询都在进行索引扫描而不是索引查找。那是因为我们在ConnectionJDBCurl中漏掉了sendStringParametersAsUnicode="false"
参数。
我们更改了连接 url 以获取所需的参数和查询 运行 非常好。
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName;packetSize=4096;sendStringParametersAsUnicode=false
我正在对现有 REST 服务进行现代化改造,并从 OnPrem 迁移到 AWS。
遗留应用程序
deployed in a OnPrem Liberty Server
MS SQL server DB was used.
Spring/Hibernate was the core technologies.
新申请详情:
Spring Boot deployed in the AWS environment in a docker container
Server-Tomcat embedded with the Spring boot.
Database is the existing MS Sql server and it is located OnPrem
一些之前执行时间不到 500 毫秒的查询现在最多需要 2000 毫秒。查询、逻辑和其他代码相关的东西在旧应用程序和新应用程序之间是相同的。我们无法找到查询为何花费更多时间的原因。
在旧应用程序中,我们使用 server.xml 配置数据源,在新应用程序中,我们在 Spring 中配置数据源] 开机 application.properties 。以下是数据源配置:
Liberty 服务器数据源:
<dataSource id="Microsoft SQL Server JDBC Driver - DataSource - JVM3" jndiName="jdbc/xxx" containerAuthDataRef="yyy" statementCacheSize="50" isolationLevel="TRANSACTION_READ_COMMITTED">
<jdbcDriver libraryRef="MSSQLJDBCLib"/>
<properties.microsoft.sqlserver databaseName="dbName" serverName="servername.com" portNumber="9999" lockTimeout="2000" packetSize="4096" sendStringParametersAsUnicode="false" trustStorePassword="{xor}" beginTranForVendorAPIs="false" freeResourcesOnClose="false" jmsOnePhaseOptimization="false" reauthentication="false" preTestSQLString="SELECT 1" validateNewConnection="false" validateNewConnectionRetryInterval="3" errorDetectionModel="ExceptionMapping" nonTransactionalDataSource="false" name="Microsoft SQL Server JDBC Driver - DataSource - JVM3" enableMultithreadedAccessDetection="false" beginTranForResultSetScrollingAPIs="false" validateNewConnectionRetryCount="100" connectionSharing="1"/>
<connectionManager agedTimeout="-1" connectionTimeout="180" maxIdleTime="300" maxPoolSize="30" minPoolSize="0" reapTime="240" purgePolicy="FailingConnectionOnly"/>
</dataSource>
Spring 引导数据源:
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName
spring.datasource.hikari.maximumPoolSize=30
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=180000
可能影响新旧应用程序之间查询性能的其他参数是什么?
注意:AWS 服务器和 OnPrem 数据库之间的 ping 时间不到 2 毫秒(可以忽略不计)。
问题已解决。我们对数据库所做的所有查询都在进行索引扫描而不是索引查找。那是因为我们在ConnectionJDBCurl中漏掉了sendStringParametersAsUnicode="false"
参数。
我们更改了连接 url 以获取所需的参数和查询 运行 非常好。
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName;packetSize=4096;sendStringParametersAsUnicode=false