简体   繁体   English

如何从功能管理与sftp的并发连接

[英]how to manage concurrent connections to sftp from function

How do we manage concurrent connections, perhaps by batching the files into the same connection? 我们如何管理并发连接,也许通过将文件批处理到同一连接中来进行管理?

I'm creating an azure function to be triggered by new blobs (this might be changed to a simple timer-trigger). 我正在创建一个由新blob触发的azure函数(可以将其更改为简单的计时器触发)。 An example of a blob would be: 一个Blob的示例为:

{
"server":"sftp.mysftpserver.com",
"credentials":"topsecret",
"body":"This text will be uploaded to the sftp server above"
}

The function will login to the server, and send the payload in the body . 该函数将登录到服务器,并在body发送有效负载。

How do we limit the number of connections that are being initiated to the same server? 我们如何限制正在启动到同一服务器的连接数?

We might have 500 blobs that are all triggering the function, which in turn is opening 500 connections to: sftp.mysftpserver.com . 我们可能有500个blob都触发了该函数,而该blob又打开了与sftp.mysftpserver.com 500个连接。

At the same time there might be just 2 blobs that are initiating connections to sftp.otherserver.net . 同时可能只有2个Blob正在启动到sftp.otherserver.net连接。

Without more info on the specific implementation I can only give general advice. 如果没有有关具体实现的更多信息,我只能提供一般性建议。 Assuming you are using some sort of FTP client, you can use a static instance of that client to share it within a Functions instance. 假设您正在使用某种FTP客户端,则可以使用该客户端静态实例在Function实例中共享它。 If throughput is that high then the Functions service will scale to multiple instances, but assuming you are on the consumption plan this will max out at 200 . 如果吞吐量那么高,那么Functions服务将扩展到多个实例,但是假设您在使用计划中,则最大值将为200 Unless there is a huge bottleneck, the a 500 document spike would likely be cleared before the scaling got anywhere near 200 instances. 除非存在巨大的瓶颈,否则在扩展达到200个实例之前,可能会清除500个文档的峰值。

For example you would do something like this: 例如,您将执行以下操作:

// Create a single, static SftpClient
private static SftpClient client = new sftpClient(endpoint, user, pass);

public static async Task Run(string input)
{
    var response = await sftpClient.SendAsync("filename.txt", input);
}

If you aren't using an SFTP library that can do this by default, you can create a static helper class that handles creating the client. 如果您不使用默认情况下可以执行此操作的SFTP库,则可以创建一个静态助手类来处理创建客户端的操作。

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

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