- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 SQL 数据读取器,它从 sql 数据库表中读取 2 列。一旦它完成了它的工作,它就会再次开始选择另外 2 列。
我会一次性完成所有工作,但这会带来一系列其他挑战。
我的问题是该表包含大量数据(大约 300 万行左右),这使得处理整个数据集有点困难。
我正在尝试验证字段值,因此我先拉出 ID 列,然后拉出其他列之一,并通过验证管道运行列中的每个值,结果存储在另一个数据库中。
我的问题是,当读者到达处理一列的末尾时,我需要强制它立即清理使用的每一小块 ram,因为这个过程使用大约 700MB 并且它有大约 200 列要处理。
如果没有完整的垃圾收集,我肯定会用完 ram。
有人知道我该怎么做吗?
我正在使用大量可重复使用的小对象,我的想法是我可以在每个读取周期结束时调用 GC.Collect() 并清除所有内容,不幸的是由于某种原因没有发生。
好的,我希望这适合,但这是有问题的方法......
void AnalyseTable(string ObjectName, string TableName)
{
Console.WriteLine("Initialising analysis process for SF object \"" + ObjectName + "\"");
Console.WriteLine(" The data being used is in table [" + TableName + "]");
// get some helpful stuff from the databases
SQLcols = Target.GetData("SELECT Column_Name, Is_Nullable, Data_Type, Character_Maximum_Length FROM information_schema.columns WHERE table_name = '" + TableName + "'");
SFcols = SchemaSource.GetData("SELECT * FROM [" + ObjectName + "Fields]");
PickLists = SchemaSource.GetData("SELECT * FROM [" + ObjectName + "PickLists]");
// get the table definition
DataTable resultBatch = new DataTable();
resultBatch.TableName = TableName;
int counter = 0;
foreach (DataRow Column in SQLcols.Rows)
{
if (Column["Column_Name"].ToString().ToLower() != "id")
resultBatch.Columns.Add(new DataColumn(Column["Column_Name"].ToString(), typeof(bool)));
else
resultBatch.Columns.Add(new DataColumn("ID", typeof(string)));
}
// create the validation results table
//SchemaSource.CreateTable(resultBatch, "ValidationResults_");
// cache the id's from the source table in the validation table
//CacheIDColumn(TableName);
// validate the source table
// iterate through each sql column
foreach (DataRow Column in SQLcols.Rows)
{
// we do this here to save making this call a lot more later
string colName = Column["Column_Name"].ToString().ToLower();
// id col is only used to identify records not in validation
if (colName != "id")
{
// prepare to process
counter = 0;
resultBatch.Rows.Clear();
resultBatch.Columns.Clear();
resultBatch.Columns.Add(new DataColumn("ID", typeof(string)));
resultBatch.Columns.Add(new DataColumn(colName, typeof(bool)));
// identify matching SF col
foreach (DataRow SFDefinition in SFcols.Rows)
{
// case insensitive compare on the col name to ensure we have a match ...
if (SFDefinition["Name"].ToString().ToLower() == colName)
{
// select the id column and the column data to validate (current column data)
using (SqlCommand com = new SqlCommand("SELECT ID, [" + colName + "] FROM [" + TableName + "]", new SqlConnection(ConfigurationManager.ConnectionStrings["AnalysisTarget"].ConnectionString)))
{
com.Connection.Open();
SqlDataReader reader = com.ExecuteReader();
Console.WriteLine(" Validating column \"" + colName + "\"");
// foreach row in the given object dataset
while (reader.Read())
{
// create a new validation result row
DataRow result = resultBatch.NewRow();
bool hasFailed = false;
// validate it
object vResult = ValidateFieldValue(SFDefinition, reader[Column["Column_Name"].ToString()]);
// if we have the relevant col definition lets decide how to validate this value ...
result[colName] = vResult;
if (vResult is bool)
{
// if it's deemed to have failed validation mark it as such
if (!(bool)vResult)
hasFailed = true;
}
// no point in adding rows we can't trace
if (reader["id"] != DBNull.Value && reader["id"] != null)
{
// add the failed row to the result set
if (hasFailed)
{
result["id"] = reader["id"];
resultBatch.Rows.Add(result);
}
}
// submit to db in batches of 200
if (resultBatch.Rows.Count > 199)
{
counter += resultBatch.Rows.Count;
Console.Write(" Result batch completed,");
SchemaSource.Update(resultBatch, "ValidationResults_");
Console.WriteLine(" committed " + counter.ToString() + " fails to the database so far.");
Console.SetCursorPosition(0, Console.CursorTop-1);
resultBatch.Rows.Clear();
}
}
// get rid of these likely very heavy objects
reader.Close();
reader.Dispose();
com.Connection.Close();
com.Dispose();
// ensure .Net does a full cleanup because we will need the resources.
GC.Collect();
if (resultBatch.Rows.Count > 0)
{
counter += resultBatch.Rows.Count;
Console.WriteLine(" All batches for column complete,");
SchemaSource.Update(resultBatch, "ValidationResults_");
Console.WriteLine(" committed " + counter.ToString() + " fails to the database.");
}
}
}
}
}
Console.WriteLine(" Completed processing column \"" + colName + "\"");
Console.WriteLine("");
}
Console.WriteLine("Object processing complete.");
}
最佳答案
你能发布一些代码吗? .NET 的数据读取器应该是一个在 RAM 上吝啬的“消防水带”,除非像弗雷迪建议的那样,您的列数据值很大。这个验证+数据库写入需要多长时间?
一般情况下,如果需要GC并且可以做,就会做。我可能听起来像是一张破唱片,但如果你必须使用 GC.Collect(),那就有其他问题了。
关于C# : Forcing a clean run in a long running SQL reader loop?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2914811/
假设我想在编译项目之前将项目本地依赖项(jar 文件)安装到本地 Maven 存储库 (~/.m2),这样我就可以在 POM 中引用它们,就像引用 Maven 中的任何依赖项一样中央。目前,我正在使用
我需要使用 Clean 编程语言列出目录中的所有文件,但我不知道这样做的任何函数。有人可以帮助我吗? 最佳答案 您可以使用 Directory module 中的函数 getDirectoryCont
我的应用程序工作正常,我能够使用 jar 执行 mvn clean install并能够执行 jar 文件,但我将其更改为 war 文件,但我无法执行 mvn clean install . 这些之间
我是 Maven 的初学者。当我点击 clean & Build 在 netbeans 中重建我的项目时,它抛出一个错误 Failed to execute goal org.apache.maven
我已经为我的一些模型覆盖了 clean() 方法来构造约束以满足我的数据库架构要求(因为它需要运行时信息来进行这些验证)。 从现在开始,我已经完成了大部分后端组件(模型、信号、..),现在我正在尝试编
从 Android Studio 项目的终端发出以下语句有什么区别: Android_Studio_Project_Path: ./gradlew clean Android_Studio_Proje
我曾在不同的团队工作过,在一个团队中,人们倾向于在合并旧分支后立即清理它们。在其他团队分支永远停留。删除/保留旧分支有什么好处?这是否取决于我们使用的源代码控制系统? (在我的情况下 - SVN)。
我有一个相当复杂的(iPhone SDK)Xcode 项目,有很多目标——4 个静态库、单元测试、多个示例应用程序、一个运行 shell 脚本的 BuildAll 以及一个运行另一个 shell 脚本
我有一个 cucumber 项目,当您单独运行 cucumberrunner 文件时,该项目运行良好 [运行方式 -->Junit 测试]。 当我尝试使用 maven 命令运行相同的文件时,它失败了:
我在 cruiseControl 中有一个 msbuild 任务,它首先清除然后重建。如果我将其更改为“清理并构建”(而不是重建),会有什么不同吗? Rebuild 为每个项目执行“清理 + 构建”。
我对 Clean Architecture 中的 Gateway to Entity 依赖有疑问。我认为以下同心圆图形经常被介绍为整洁的架构。 在上图中,Gateway并没有直视Entity。但是,还
我使用M2e + Eclipse + Maven,我想知道两者之间的区别: 在终端和中运行“mvn clean” 从Eclipse 运行“干净的项目”吗? 有人可以请教吗? 最佳答案 通过一些快速测试
我试图弄清楚 package.json 脚本部分中“clean:dist”或“clean:js”与“clean”的作用?我在网上搜索并查看了NPM documentation但找不到任何线索。那么有人
我在 Linux 上的构建过程有一个小问题。 无论出于何种原因,在我的代码中,如果我发出“make clean”命令,Linux 会生成一个名为“clean”的文件。问题是我的项目的 makefile
mvn clean package和mvn clean install到底有什么区别?当我运行这两个命令时,它们似乎都在做同样的事情。 最佳答案 好吧,两者都会清理。这意味着他们将删除目标文件夹。真正
您在每个应用程序的开发过程中都遇到了某个时刻,您在模拟器中看到的内容与您认为应该发生的情况不符。这些大多是人为错误——或者至少在大多数我的案例中是这样的;-)——但有时 Xcode 只是“迷失了方向”
我使用这两个命令来解决我项目中的依赖问题。 mvn -U clean compile解决的问题。但我不知道它们之间的区别。请解释这些命令之间的区别以及我何时使用 mvn clean compile和
我正在为我的项目使用 Maven。如果我的项目不使用某些本地资源,这不是问题。 以便我遵循本指南 https://stackoverflow.com/a/61576687/6720896 将我的本地
我正在尝试创建一个 Grunt 任务来清理目录中的所有文件、子目录及其文件等。 我可以删除所有文件,但文件夹始终保留。 clean: { preview: ["live_previe
我有以下情况: 我有一个包含几个子项目的项目。今天我尝试通过命令行使用 gradle 构建项目。 执行 ./gradlew clean :build 时构建成功, 但不是 ./gradlew clea
我是一名优秀的程序员,十分优秀!