简体   繁体   English

SqlBulkCopy是高效单行插入的错误选择吗?

[英]Is SqlBulkCopy the wrong choice for efficient single row inserts?

Good Morning. 早上好。

I have an a service I am writing in C# that performs and insert of a single row every 15 seconds or so. 我有一个用C#编写的服务,该服务每15秒左右执行一次并插入一行。 This interval is user-definable but at the moment 15 seconds is the targeted interval. 此间隔是用户可定义的,但目前15秒钟是目标间隔。

I have read this article: SqlBulkCopy on a single record? 我已经读过这篇文章: SqlBulkCopy在单个记录上吗? which does explain clearly the throughput benefits of using a regular insert over performing a single row bulk insert. 确实清楚地说明了使用常规刀片优于执行单行批量插入的吞吐量优势。 But it also mentions (or implies) that the regular insert is a bit a heavier on CPU than the bulk insert. 但是它也提到(或暗示)常规插入在CPU上比批量插入要重一些。

As the service I Am writing is a support service, and as the insert is artificially restricted to only 1 in a given interval I am wondering if whether the implication above is justification for using SqlBulkCopy over a regular insert. 由于我正在编写的服务是一项支持服务,并且由于在给定的时间间隔内人为地将插入限制为1,所以我想知道上面的含义是否是在常规插入上使用SqlBulkCopy的理由。 Obviously I want my service to be as lightweight as possible. 显然,我希望我的服务尽可能轻巧。

The answer in your article says the SqlBulkCopy is 4.4x slower and take double the CPU of a simple SQL Command. 您文章中的答案说SqlBulkCopy慢4.4倍,占用的CPU数量是简单SQL命令的两倍。 You misread the answer (or I did), it states SqlBulkCopy is heavier on CPU than a regular insert which makes more sense. 您误解了答案(或者我做错了),它指出SqlBulkCopy在CPU上比常规插入要重,这更有意义。

The answer is simple: Stick with SQL Command if you are 100% sure only one record need to be inserted. 答案很简单:如果您100%确定只需要插入一条记录,则坚持使用SQL命令。

Even my library C# Bulk Operations do not use SqlBulkCopy until it reaches a specific amount of row which is normally ten because SqlBulkCopy is too heavy. 甚至我的库C#批量操作也不会使用SqlBulkCopy,直到达到特定数量的行(通常为十),这是因为SqlBulkCopy太重了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM