当前位置: 首页 > news >正文

关于 PreparedStatement

Mysql 层面的语法也支持 prepare
这个确实第一次见

  • PREPARE prepares a statement for execution (see Section 13.5.1, “PREPARE Statement”).
  • EXECUTE executes a prepared statement (see Section 13.5.2, “EXECUTE Statement”).
  • DEALLOCATE PREPARE releases a prepared statement (see Section 13.5.3, “DEALLOCATE PREPARE Statement”).
mysql> PREPARE stmt1 FROM 'SELECT * FROM words where id = ?';
Query OK, 0 rows affected (0.00 sec)
Statement preparedmysql> SET @i=1;
Query OK, 0 rows affected (0.00 sec)
mysql> EXECUTE stmt1 USING @i;
Empty set (0.01 sec)mysql> SET @i=2;
Query OK, 0 rows affected (0.00 sec)
mysql> EXECUTE stmt1 USING @i;
+----+------+
| id | word |
+----+------+
|  2 | 123  |
+----+------+
1 row in set (0.00 sec)mysql> deallocate prepare stmt1;
Query OK, 0 rows affected (0.00 sec)mysql> EXECUTE stmt1 USING @i;
ERROR 1243 (HY000): Unknown prepared statement handler (stmt1) given to EXECUTE

useServerPrepStmts=true

useServerPrepStmts

Use server-side prepared statements if the server supports them?

Default: false

Since version: 3.1.0

如果我们没有在 jdbc 参数中声明这个参数、即使我们在代码中使用了 PreparedStatement 实际上是毫无作用的

    try (PreparedStatement psts = conn.prepareStatement("delete from words where id = ?")) {psts.setInt(1, 1);psts.execute();stopwatch.stop();System.out.println("stopwatch = " + stopwatch.elapsed(TimeUnit.MILLISECONDS));psts.setInt(1, 10);psts.execute();} 

抓包看看

在这里插入图片描述

mysql general log:

2020-05-04T13:06:07.883131Z	   15 Connect	root@localhost on test using TCP/IP
2020-05-04T13:06:07.885668Z	   15 Query	/* mysql-connector-java-8.0.16 (Revision: 34cbc6bc61f72836e26327537a432d6db7c77de6) */SELECT  @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout
2020-05-04T13:06:07.905021Z	   15 Query	SET character_set_results = NULL
2020-05-04T13:06:07.929557Z	   15 Query	delete from words where id = 1
2020-05-04T13:06:07.934906Z	   15 Query	delete from words where id = 10
2020-05-04T13:06:07.940645Z	   15 Quit

当我们使用 useServerPrepStmts=true 之后

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

log

2020-05-04T13:15:55.611149Z	   16 Connect	root@localhost on test using TCP/IP
2020-05-04T13:15:55.615655Z	   16 Query	/* mysql-connector-java-8.0.16 (Revision: 34cbc6bc61f72836e26327537a432d6db7c77de6) */SELECT  @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout
2020-05-04T13:15:55.640086Z	   16 Query	SET character_set_results = NULL
2020-05-04T13:15:55.672345Z	   16 Prepare	delete from words where id = ?
2020-05-04T13:15:55.676355Z	   16 Execute	delete from words where id = 1
2020-05-04T13:15:55.681600Z	   16 Execute	delete from words where id = 10
2020-05-04T13:15:55.681949Z	   16 Close stmt
2020-05-04T13:15:55.687659Z	   16 Quit

cachePrepStmts

客户端 connection 级别缓存预编译的 sql

@Test
@SneakyThrows
public void testPreCompile() {String connectString = "jdbc:mysql://localhost/test?user=root&password=toor&useLocalSessionState=true&useSSL=false&useServerPrepStmts=true&cachePrepStmts=true";Class.forName("com.mysql.jdbc.Driver").newInstance();try (Connection conn = DriverManager.getConnection(connectString)) {Stopwatch stopwatch = Stopwatch.createStarted();try (PreparedStatement psts = conn.prepareStatement("delete from words where id = ?")) {psts.setInt(1, 1);psts.execute();stopwatch.stop();System.out.println("stopwatch = " + stopwatch.elapsed(TimeUnit.MILLISECONDS));psts.setInt(1, 10);psts.execute();}// 上面的stmt关闭之后,再次执行try (PreparedStatement psts = conn.prepareStatement("delete from words where id = ?")) {psts.setInt(1, 100);psts.execute();}}// 上面的connection关闭之后,再次执行try (Connection conn = DriverManager.getConnection(connectString)) {try (PreparedStatement psts = conn.prepareStatement("delete from words where id = ?")) {psts.setInt(1, 66);psts.execute();}}}

在这里插入图片描述

2020-05-04T15:17:32.921041Z	   19 Connect	root@localhost on test using TCP/IP
2020-05-04T15:17:32.929561Z	   19 Query	/* mysql-connector-java-8.0.16 (Revision: 34cbc6bc61f72836e26327537a432d6db7c77de6) */SELECT  @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout
2020-05-04T15:17:32.949986Z	   19 Query	SET character_set_results = NULL
2020-05-04T15:17:32.983173Z	   19 Prepare	delete from words where id = ?
2020-05-04T15:17:32.990498Z	   19 Execute	delete from words where id = 1
2020-05-04T15:17:32.997115Z	   19 Execute	delete from words where id = 10
2020-05-04T15:17:32.997566Z	   19 Reset stmt
2020-05-04T15:17:32.997725Z	   19 Execute	delete from words where id = 100
2020-05-04T15:17:33.003682Z	   19 Quit
2020-05-04T15:17:33.009206Z	   20 Connect	root@localhost on test using TCP/IP
2020-05-04T15:17:33.009643Z	   20 Query	/* mysql-connector-java-8.0.16 (Revision: 34cbc6bc61f72836e26327537a432d6db7c77de6) */SELECT  @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout
2020-05-04T15:17:33.010569Z	   20 Query	SET character_set_results = NULL
2020-05-04T15:17:33.011244Z	   20 Prepare	delete from words where id = ?
2020-05-04T15:17:33.011475Z	   20 Execute	delete from words where id = 66
2020-05-04T15:17:33.114892Z	   20 Quit

我们直接来看看它是怎么存储的

在这里插入图片描述

在这里插入图片描述

既然是缓存、肯定涉及到缓存的个数以及单个缓存值的大小

prepStmtCacheSize & prepStmtCacheSqlLimit

prepStmtCacheSize 默认值为 25 注意这里是一个 connection 下最多缓存 25 个预编译的 Statement

prepStmtCacheSqlLimit 默认是 256 单纯就是 sql 的长度

在这里插入图片描述

源码

在这里插入图片描述

com.mysql.cj.jdbc.ConnectionImpl#prepareStatement(java.lang.String, int, int)

    @Overridepublic java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {synchronized (getConnectionMutex()) {checkClosed();//// FIXME: Create warnings if can't create results of the given type or concurrency//ClientPreparedStatement pStmt = null;boolean canServerPrepare = true;String nativeSql = this.processEscapeCodesForPrepStmts.getValue() ? nativeSQL(sql) : sql;// useServerPrepStmts 属性if (this.useServerPrepStmts.getValue() && this.emulateUnsupportedPstmts.getValue()) {canServerPrepare = canHandleAsServerPreparedStatement(nativeSql);}if (this.useServerPrepStmts.getValue() && canServerPrepare) {// cachePrepStmts 缓存预编译 Statementif (this.cachePrepStmts.getValue()) {synchronized (this.serverSideStatementCache) {// 从缓存中获取pStmt = this.serverSideStatementCache.remove(new CompoundCacheKey(this.database, sql));if (pStmt != null) {// 强转为ServerPreparedStatement,清理参数,直接返回((com.mysql.cj.jdbc.ServerPreparedStatement) pStmt).setClosed(false);pStmt.clearParameters();}if (pStmt == null) {try {pStmt = ServerPreparedStatement.getInstance(getMultiHostSafeProxy(), nativeSql, this.database, resultSetType,resultSetConcurrency);if (sql.length() < this.prepStmtCacheSqlLimit.getValue()) {((com.mysql.cj.jdbc.ServerPreparedStatement) pStmt).isCacheable = true;}pStmt.setResultSetType(resultSetType);pStmt.setResultSetConcurrency(resultSetConcurrency);} catch (SQLException sqlEx) {// Punt, if necessaryif (this.emulateUnsupportedPstmts.getValue()) {pStmt = (ClientPreparedStatement) clientPrepareStatement(nativeSql, resultSetType, resultSetConcurrency, false);if (sql.length() < this.prepStmtCacheSqlLimit.getValue()) {this.serverSideStatementCheckCache.put(sql, Boolean.FALSE);}} else {throw sqlEx;}}}}} else {try {pStmt = ServerPreparedStatement.getInstance(getMultiHostSafeProxy(), nativeSql, this.database, resultSetType, resultSetConcurrency);pStmt.setResultSetType(resultSetType);pStmt.setResultSetConcurrency(resultSetConcurrency);} catch (SQLException sqlEx) {// Punt, if necessaryif (this.emulateUnsupportedPstmts.getValue()) {pStmt = (ClientPreparedStatement) clientPrepareStatement(nativeSql, resultSetType, resultSetConcurrency, false);} else {throw sqlEx;}}}} else {pStmt = (ClientPreparedStatement) clientPrepareStatement(nativeSql, resultSetType, resultSetConcurrency, false);}return pStmt;}}

close 的时候会重新放回去缓存

// com.mysql.cj.jdbc.ServerPreparedStatement#close@Override
public void close() throws SQLException {JdbcConnection locallyScopedConn = this.connection;if (locallyScopedConn == null) {return; // already closed}synchronized (locallyScopedConn.getConnectionMutex()) {if (this.isCached && isPoolable() && !this.isClosed) {clearParameters();this.isClosed = true;// 重新缓存起来this.connection.recachePreparedStatement(this);return;}this.isClosed = false;realClose(true, true);}
}// com.mysql.cj.jdbc.ConnectionImpl#recachePreparedStatement@Overridepublic void recachePreparedStatement(JdbcPreparedStatement pstmt) throws SQLException {synchronized (getConnectionMutex()) {if (this.cachePrepStmts.getValue() && pstmt.isPoolable()) {synchronized (this.serverSideStatementCache) {Object oldServerPrepStmt = this.serverSideStatementCache.put(new CompoundCacheKey(pstmt.getCurrentCatalog(), ((PreparedQuery<?>) pstmt.getQuery()).getOriginalSql()),(ServerPreparedStatement) pstmt);if (oldServerPrepStmt != null && oldServerPrepStmt != pstmt) {((ServerPreparedStatement) oldServerPrepStmt).isCached = false;((ServerPreparedStatement) oldServerPrepStmt).setClosed(false);((ServerPreparedStatement) oldServerPrepStmt).realClose(true, true);}}}}}

关于 PSCache

这个是关于 druid 的

争议较大的是 mysql 的时候是否开启 PSCache、下面 github 的 issue 是处于 open 状态

// com.alibaba.druid.pool.DruidPooledConnection#closePoolableStatement
public void closePoolableStatement(DruidPooledPreparedStatement stmt) throws SQLException {PreparedStatement rawStatement = stmt.getRawPreparedStatement();if (holder == null) {return;}if (stmt.isPooled()) {try {rawStatement.clearParameters();} catch (SQLException ex) {this.handleException(ex, null);if (rawStatement.getConnection().isClosed()) {return;}LOG.error("clear parameter error", ex);}}PreparedStatementHolder stmtHolder = stmt.getPreparedStatementHolder();stmtHolder.decrementInUseCount();// holder.isPoolPreparedStatements 对应上面配置的开关if (stmt.isPooled() && holder.isPoolPreparedStatements() && stmt.exceptionCount == 0) {// 放入缓存池子中holder.getStatementPool().put(stmtHolder);stmt.clearResultSet();holder.removeTrace(stmt);stmtHolder.setFetchRowPeak(stmt.getFetchRowPeak());stmt.setClosed(true); // soft set close} else if (stmt.isPooled() && holder.isPoolPreparedStatements()) {// the PreparedStatement threw an exceptionstmt.clearResultSet();holder.removeTrace(stmt);// 开启了PSCache但是这个stmt抛出过异常,直接从缓存中移除holder.getStatementPool().remove(stmtHolder);} else {try {//Connection behind the statement may be in invalid state, which will throw a SQLException.//In this case, the exception is desired to be properly handled to remove the unusable connection from the pool.stmt.closeInternal();} catch (SQLException ex) {this.handleException(ex, null);throw ex;} finally {holder.getDataSource().incrementClosedPreparedStatementCount();}}
}

https://qsli.github.io/2020/05/05/cache-prep-stmts/

https://github.com/alibaba/druid/issues/2273

相关文章:

关于 PreparedStatement

Mysql 层面的语法也支持 prepare 这个确实第一次见 PREPARE prepares a statement for execution (see Section 13.5.1, “PREPARE Statement”).EXECUTE executes a prepared statement (see Section 13.5.2, “EXECUTE Statement”).DEALLOCATE PREPARE releases a prepared…...

漫谈设计模式 [9]:外观模式

引导性开场 菜鸟&#xff1a;老鸟&#xff0c;我最近在做一个项目&#xff0c;感觉代码越来越复杂&#xff0c;我都快看不懂了。尤其是有好几个子系统&#xff0c;它们之间的调用关系让我头疼。 老鸟&#xff1a;复杂的代码确实让人头疼。你有没有考虑过使用设计模式来简化你…...

多进程编程

基本概念 进程是一个具有单独功能的程序对某个数据集在处理机上的执行过程&#xff0c;进程也是作为资源分配的一个单位。 进程和程序是相辅相成的&#xff0c;进程是一个动态概念。 进程具有并行性特征。进程具有独立性和异步性。 进程的描述 进程分为三部分&#xff1a;…...

7-Zip压缩包如何添加密码,加密后如何取消

压缩包文件大家经常使用&#xff0c;最熟悉的肯定是RAR、ZIP格式压缩文件&#xff0c;但是7z压缩文件格式也很好用&#xff0c;它是三种压缩文件格式中压缩率最大的。想要将文件压缩到最小&#xff0c;使用7z格式可以达到最大化。那么在使用7z压缩格式的时候&#xff0c;我们可…...

HarmonyOS---应用测试概述

一、应用质量要求 应用质量要求分为应用体验质量建议和应用内容合规要求两大部分。 1、应用体验质量建议 功能数据完备、基础体验要求、HarmonyOS特征增强体验要求。 &#xff08;1&#xff09;功能数据完备 &#xff08;2&#xff09;基础体验要求 &#xff08;3&#xff09;增…...

密码学---真题演练

✨Base加密&#xff1a;题目-base? 靶场网址&#xff1a;https://polarctf.com/ Base100加密&#xff01;&#xff01;&#xff01; 得到的新的一串密码是 rot47 密码&#xff0c;属于凯撒密码的一种变体. ✨斐波那契&#xff1a;题目-FB 从第三项开始&#xff0c;每一项都等…...

时间日期工具类

时间日期工具类 import java.time.*; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit;public class DateTimeUtils {private static final String DEFAULT_DATE_FORMAT "yyyy-MM-dd";private static final String DEFAULT_TIME_…...

linux中vim常用命令大全

前言 Linux有大量的配置文件&#xff0c;所以 Linux的文本处理工具也是比较多的&#xff0c;其中编辑一些配置文件时&#xff0c;常用的工具就是 vim。在Linux中&#xff0c;Vim编辑器是一个非常强大的文本编辑工具&#xff0c;它提供了多种模式和命令来满足不同的编辑需求。以…...

计算机的错误计算(八十九)

摘要 探讨反双曲余切函数 acoth(x) 在 附近的计算精度问题。 Acoth(x) 函数的定义为&#xff1a; 其中 x 的绝对值大于 1 . 例1. 计算 acoth(1.000000000002) . 不妨在 Excel 的单元格中计算&#xff0c;则有&#xff1a; 若在Python中用定义直接计算&#xff0c;则有几乎…...

深入理解java并发编程之aqs框架

跟synchronized 相比较&#xff0c;可重入锁ReentrankLock其实原理有什么不同&#xff1f; 所得基本原理是为了达到一个目的&#xff1b;就是让所有线程都能看到某种标记。synchronized通过在对象头中设置标记实现了这一目的&#xff0c;是一种JVM原生的锁实现方式。而Reentran…...

ubuntu配置tftp、nfs

tftp配置 tftp是简单文件传输协议&#xff0c;基于udp实现传输。这里的简单文件&#xff0c;指的是不复杂、开销不大的文件。 先在ubuntu中安装tftp&#xff0c;输入命令&#xff1a;sudo apt-get install tftp-hpa tftpd-hpa。 接着配置tftp。 输入命令&#xff1a;sudo v…...

Sklearn的datasets模块与自带数据集介绍

datasets 模块 用 dir() 函数查看 datasets 模块的所有属性和函数 import sklearn.datasets as datasets# 列出 sklearn.datasets 模块中的所有属性和函数 print(dir(datasets)) datasets 模块下的数据集有三种类型&#xff1a; &#xff08;1&#xff09;load系列的经典数…...

css 个人喜欢的样式 速查笔记

起因&#xff0c; 目的: 记录自己喜欢的&#xff0c; 觉得比较好看的 css. 下次用的时候&#xff0c;直接复制&#xff0c;很方便。 1. 个人 html 模板&#xff0c; 导入常用的 link 设置英语字体: Noto导入默认的 css使用网络 icon 图标导入 Bootstrap css 框架 html <…...

C/C++ let __DATE__ format to “YYYY-MM-DD“

C/C let DATE format to “YYYY-MM-DD” code&#xff1a; #include <iostream> #include <string>class compileDate {// 静态函数&#xff0c;用来格式化并返回编译日期 static std::string formatCompileDate() {// 编译时的日期&#xff0c;格式为 "MMM…...

git如何灵活切换本地账号对应远程github的两个账号

git如何灵活切换本地账号对应远程github的两个账号 问题&#xff1a; 有时候我们会同时维护两个github的账号里面的仓库内容&#xff0c;这时候本地git需要频繁的切换ssh&#xff0c;以方便灵活的与两个账号的仓库可以通信。这篇日记将阐述我是怎么解决这个问题的。1. 第一个账…...

Python中实现函数的递归调用

在Python中&#xff0c;函数的递归调用是一种非常强大且常用的编程技巧&#xff0c;它允许函数在其执行过程中调用自身。递归调用在解决许多问题时都显得尤为方便&#xff0c;比如遍历树形结构、计算阶乘、实现快速排序等。然而&#xff0c;递归也需要谨慎使用&#xff0c;因为…...

Multisim使用手册

目录 原件库&#xff1a; 基础元件库&#xff1a; 最右侧的分析仪们&#xff1a; 示波器&#xff1a; 交流分析&#xff1a; 操作&#xff1a; dB 一、幅频特性曲线 二、相频特性曲线 下载资源&#xff08;有汉化&#xff09;&#xff1a;Multisim 14.0电路设计与仿真…...

线程的六种状态

优质博文&#xff1a;IT-BLOG-CN 线程的状态在Thread.State这个枚举类型中定义&#xff1a;共有6种状态&#xff0c;可以调用线程Thread种的getState()方法获取当前线程状态。 public enum State { /** * 新建状态(New)&#xff1a; * 当用new操作符创建一个线程时&#…...

全球热门剪辑软件大搜罗

如果你要为你的视频进行配音那肯定离不开音频剪辑软件&#xff0c;现在有不少音频剪辑软件免费版本就可以实现我们并不复杂的音频剪辑操作。这次我就给你分享几款能提高剪辑效率的音频剪辑工具。 1.福晰音频剪辑 链接直达>>https://www.foxitsoftware.cn/audio-clip/ …...

swagger-bootstrap-ui页面空白,也没报错

回想起来&#xff0c;代码层面没有进行什么大的调整&#xff0c;增加了配置文件&#xff0c;application.yml中的 spring:profiles:active: sms # dev --> smsname: sms-server swagger配置未调整导致空白 修改profile 问题解决...

15.2 JDBC数据库编程2

15.2.1 数据库访问步骤 使用JDBC API连接和访问数据库&#xff0c;一般分为以下5个步骤: (1) 加载驱动程序 (2) 建立连接对象 (3) 创建语句对象 (4) 获得SQL语句的执行结果 (5) 关闭建立的对象&#xff0c;释放资源 下面将详细描述这些步骤 15.2.2 加载驱动程序 要使…...

Spark数据介绍

从趋势上看&#xff0c;DataFrame 和 Dataset 更加流行。 示例场景 数据仓库和 BI 工具集成&#xff1a; 如果你需要处理存储在数据仓库中的结构化数据&#xff0c;并且希望与 BI 工具集成&#xff0c;那么 DataFrame 和 Dataset 是首选。 机器学习流水线&#xff1a; 在构建机…...

【0基础】制作HTML网页小游戏——贪吃蛇(附详细解析)

我在昨天的文章&#xff08;贪吃蛇HTML源码&#xff09;里面分享了网页版贪吃蛇小游戏的源码&#xff0c;今天就来给大家详细讲解一下每部分代码是如何运作的&#xff0c;以及以后要如何美化贪吃蛇的UI界面&#xff0c;在哪里修改等。 目录 一、代码运作 1、HTML结构: 2、C…...

Vscode python无法转到函数定义

今天上午换了电脑&#xff0c;使用Vscode发现找不到对应的函数定义了。 使用了网上的全部教程。一点用没有。重启电脑&#xff0c;重启Vscode也没有作用。最后通过重装vscode&#xff0c;解决问题。&#xff08;也不知道Vscode什么毛病&#xff09; 重点语句&#xff1a; 去官网…...

Python中的上下文管理器(with语句)及其作用

Python中的上下文管理器&#xff08;Context Manager&#xff09;是一种通过with语句来管理资源&#xff08;如文件、网络连接、线程锁等&#xff09;的机制。with语句旨在简化常见的资源管理任务&#xff0c;如资源的获取、使用后的清理等。使用上下文管理器可以确保资源在使用…...

CTK框架(八):服务追踪

目录 1.简介 2.实现方式 3.具体实现 3.1.新建插件PluginA​​ 3.2.新建插件PluginB 4.服务追踪的优势 5.应用场景 6.总结 1.简介 CTK服务追踪是一种机制&#xff0c;用于在CTK插件框架中追踪和管理插件提供的服务。当一个插件注册了一个服务到服务注册中心后&#xff0…...

[针对于个人用户] 显卡与计算卡性能对比表

笔者使用 Quadro M4000 显卡用于 LLM 相关任务&#xff0c;但奈何该卡发布的年代过于久远&#xff0c;以至于 LLM 相关任务只能使用例如&#xff1a;Phi3 mini、Qwen 2 2B、GLM 4 8B 以及 Gemini v2 2B等小参数模型&#xff0c;且速度不堪理想&#xff0c;也经常因为显卡过热降…...

2024年智能录屏解决方案全攻略,从桌面到云端

如果你有过录屏经验那你一定遇到过被限制录制时长或者录制的画面比较模糊之类的情况。这次我我推荐几款免费录屏软件&#xff0c;让我们可以更自由的录制屏幕画面。 1.福晰REC大师 链接&#xff1a;www.foxitsoftware.cn/REC/ 这款软件便捷好操作&#xff0c;而且符合我这次…...

CentOS7.9下snmp v3 inform搭建监控端

1.基础环境配置 为了防止防火墙及selinux等的影响,需关闭防火墙及selinux等,具体参考: Linux常规基础配置_linux基础配置-CSDN博客 2.安装snmp yum源配置,具体参考: Linux常规基础配置_linux基础配置-CSDN博客 snmp安装命令: yum install -y net-snmp net-snmp-ut…...

水库大坝安全监测方案,双重守护,安全无忧

水库作为重要的水利设施&#xff0c;在防洪、灌溉及供水等方面发挥着重要作用。然而随着时间的推移&#xff0c;大坝面临着自然老化、设计标准不足及极端天气等多重挑战&#xff0c;其安全性与稳定性日益受到关注。水库堤坝险情导致的洪涝灾害给人民生命财产和经济社会发展带来…...