Web应用程序接收数百万个请求,并导致在SQL Server 2008中每30秒生成数百万行插入(web application receiving millions of requests and leads to generating millions of row inserts per 30 seconds in SQL Server 2008)
我目前正在解决我们的Web应用程序每30秒至少收到一百万个请求的情况。 因此,这些请求将导致在5个表之间生成3-5百万行插入。 这是非常重要的负担。 目前我们正在使用多线程来处理这种情况(速度稍快但无法获得更好的CPU吞吐量)。 然而,未来负荷肯定会增加,我们也必须考虑到这一点。 从现在起6个月后,我们正在考虑我们目前正在接收的负载大小的两倍,我目前正在寻找一种可扩展的可能新解决方案,并且应该足够容易以适应此负载的任何进一步增加。 目前使用多线程我们正在使整个调试场景变得非常复杂,有时我们遇到跟踪问题的问题。
仅供参考我们已经在使用上一篇文章中提到的SQL Builk插入/复制
Sql server 2008 - 用于插入大量数据的性能调整功能
但是我正在寻找能够解决这种情况的更有能力的解决方案(我认为应该有一个)。
注意:我不是在寻找任何代码片段或代码示例。 我只是在寻找一个我可以使用的概念的大图,我相信我可以进一步采用优雅的解决方案:)
此外,解决方案应该更好地利用线程和进程。 而且我不希望我的线程/进程因为其他资源而等待执行某些事情。
任何建议都将深表感谢。
更新 :并非每个请求都会导致插入...但是大多数请求都会导致一些SQL操作。 应用程序执行不同类型的事务,这将导致大量的批量SQL操作。 我更关注插入和更新。 并且这些操作不需要是实时的,可能会有一点滞后......但是实时处理它们会非常有用。
I am currently addressing a situation where our web application receives at least a Million requests per 30 seconds. So these requests will lead to generating 3-5 Million row inserts between 5 tables. This is pretty heavy load to handle. Currently we are using multi threading to handle this situation (which is a bit faster but unable to get a better CPU throughput). However the load will definitely increase in future and we will have to account for that too. After 6 months from now we are looking at double the load size we are currently receiving and I am currently looking at a possible new solution that is scalable and should be easy enough to accommodate any further increase to this load. Currently with multi threading we are making the whole debugging scenario quite complicated and sometimes we are having problem with tracing issues.
FYI we are already utilizing the SQL Builk Insert/Copy that is mentioned in this previous post
Sql server 2008 - performance tuning features for insert large amount of data
However I am looking for a more capable solution (which I think there should be one) that will address this situation.
Note: I am not looking for any code snippets or code examples. I am just looking for a big picture of a concept that I could possibly use and I am sure that I can take that further to an elegant solution :)
Also the solution should have a better utilization of the threads and processes. And I do not want my threads/processes to even wait to execute something because of some other resource.
Any suggestions will be deeply appreciated.
Update: Not every request will lead to an insert...however most of them will lead to some sql operation. The appliciation performs different types of transactions and these will lead to a lot of bulk sql operations. I am more concerned towards inserts and updates. and these operations need not be real time there can be a bit lag...however processing them real time will be much helpful.
原文:https://stackoverflow.com/questions/5584671
最满意答案
Cloud Functions无法像以前一样大规模扩展, 并且仍然在本地读取数据库。 为您的功能启动的每个服务器实例都是该功能的独立环境。 如果您的功能访问实时数据库或Firestore,它将通过Google的内部网络执行此操作。
如果您对性能有所顾虑,则应根据您的预期情况对其进行基准测试。 没有人可以做出任何猜测,如果它没有一些具体的数据可以“足够快”。
There is no way that Cloud Functions could scale massively as it does and still read your database locally. Each server instance that's spun up for your functions is an isolated environment for that function. If your function accesses Realtime Database or Firestore, it will be doing so over Google's internal networks.
If you have concerns about performance, you should benchmark it according to your expected situation. No one can make any guesses if it's going to be "fast enough" without some concrete data to work with.
相关问答
更多-
Cloud Functions无法像以前一样大规模扩展, 并且仍然在本地读取数据库。 为您的功能启动的每个服务器实例都是该功能的独立环境。 如果您的功能访问实时数据库或Firestore,它将通过Google的内部网络执行此操作。 如果您对性能有所顾虑,则应根据您的预期情况对其进行基准测试。 没有人可以做出任何猜测,如果它没有一些具体的数据可以“足够快”。 There is no way that Cloud Functions could scale massively as it does and st ...
-
Firebase的云功能 - 这与解析中的“云代码”类似吗?(Cloud Functions for Firebase - Is this similar to “Cloud Code” in parse?)[2023-10-17]
1)每个函数调用应该完全相互隔离。 没有始终可用的“共享状态”,这意味着没有共享内存缓存或共享本地文件。 这是产品自动扩展的唯一方法。 如果您需要云功能中的数据,您必须找到获取它的方法,这可能是一些查询。 2)有很多关于这个主题的文章。 搜索对你有好处。 有关一些选项,请参阅示例代码和此Firebase博客 。 目前没有本机支持的调度机制,因此您现在需要自己构建一个。 1) Each function invocation should be expected to run completely isola ... -
Firebase的云功能 - event.data读取特殊值(Cloud Functions for Firebase - event.data read special value)[2022-03-13]
当前函数将触发/fruits下的任何更改。 所以没有当前的 fruitID值。 如果您想在特定水果写入时触发,您需要将触发器更改为fruits/{fruidId} 。 这也使得您的代码中的fruitId值可用: exports.newFruit = functions.database.ref("fruits/{fruitId}").onWrite(event => { if (!event.data.previous.exists()) { var newFruitKey = event.pa ... -
那么,解决方案是使用管理员而不是firebase,如下所示: admin.database().ref('...').once('value').then(function(snapshot) { ... }); Well, the solution is to use admin instead of firebase like so: admin.database().ref('...').once('value').then(function(snapshot) { ... });
-
在您的情况下, event.data.val()显然不返回数字。 它返回一个对象,你在日志中看到。 如果您使用console.log(ticketsBoughtByUser) (不要使用字符串连接来构建消息),您实际上可以看到对象中的数据。 对于你在数据库中显示的数据,我希望val是一个包含这些数据的对象(编辑过的,所以我不必输入它): { "oeb...IE2": 1 } 如果你想从对象中获取1 ,那么你必须使用字符串键进入它,无论该字符串表示什么: const num = ticketsBou ...
-
Cloud Functions中的诀窍是使用once('value' ,它可以同时为您提供所有匹配的节点。 exports.readStore = functions.database.ref('/categories/{userId}') .onWrite(event => { let query = admin.database().ref(`categories/${event.params.userId}`).orderByChild('name'); return query.once( ...
-
如何使用新的Firebase云功能读取数据?(How can I just read data using the new Cloud Functions for Firebase?)[2021-10-30]
您不能使用functions.database.ref()来读取数据。 这仅用于指定要更改数据库以触发功能的路径。 要编写类似cron的函数,您不会编写数据库触发器。 您可能需要HTTP触发器,如示例代码所示。 如自述文件中所述,您使用第三方调度程序触发HTTP功能。 要从该函数中的数据库中读取数据,您应该使用admin SDK,如该代码示例所示。 它在这里初始化,并出现在许多其他代码示例中: const admin = require('firebase-admin'); admin.initialize ... -
除Matts答案外,您还需要调整逻辑。 exports.keepPostKeysUpdated = functions.database.ref('/posts/{postid}').onWrite(event => { // When a table, category, or region is changed the old upload has to be deleted if (event.data.previous.exists()) { var postKey = eve ...
-
使用HTTPS触发器,如下所述: https : //firebase.google.com/docs/functions/http-events 另外,请查看此官方示例: https : //github.com/firebase/functions-samples/tree/master/quickstarts/time-server exports.unguessableFunctionName = functions.https.onRequest((req, res) => { return ...
-
在编写数据库触发器函数时,该事件包含两个属性,这两个属性是对已更改数据位置的引用: event.data.ref event.data.adminRef ref仅限于触发该功能的用户的权限。 adminRef具有对数据库的完全访问权限。 每个Reference对象都有一个root属性,可以为您提供对数据库根目录的引用。 您可以使用该引用在数据库的另一部分中构建引用的路径,并使用once()方法读取它。 您还可以使用Firebase管理SDK。 您可能应该查看许多代码示例 。 When writing a ...