我当前正在进行的项目需要多个进程将数据上传到 S3 中的单个文件。这些数据并行来自多个源,因此为了尽快处理所有源,我们将使用多个 Nodejs 实例来监听源。由于存在内存和存储限制,因此将所有摄取的数据加载到内存或存储在磁盘中,然后执行单次上传是不可能的。
为了遵守这些限制,我实现了流式上传:它缓冲来自单个源的一小部分数据,并将缓冲区传输到上传流。当使用单个 Nodejs 进程时,这非常有效,但是,正如我提到的,目标是并行处理所有源。我的第一次尝试是打开多个流到存储桶中的同一对象键。这只是用最后一个要关闭的流中的数据覆盖该文件。所以我放弃了这个选项。
// code for the scenario above, where each process will open a separete stream to
// the same key and perform it's data ingestion and upload.
openStreamingUpload() {
const stream = require('stream');
const AWS = require('aws-sdk');
const s3 = new this.AWS.S3(/* s3 config */);
const passThrough = new stream.PassThrough();
const params = {
Key: 'final-s3-file.txt',
Bucket: 'my-bucket',
Body: passThrough
};
s3
.upload(params)
.promise();
return passThrough;
}
async main() { // simulating a …
Run Code Online (Sandbox Code Playgroud) 正如来自这个问题和本教程的用户所解释的那样,我正在尝试设置一个简单的 ssh 连接以在应用程序上执行单个命令。它甚至不需要等待任何响应。
这是代码:
主要活动:包 com.example.lucas.shutdown;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onCLick(View v){
new AsyncTask<Integer, Void, Void>(){
@Override
protected Void doInBackground(Integer... params) {
try {
executeRemoteShutdown();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute(1);
}
public void executeRemoteShutdown(){
String user = "ssh";
String password = …
Run Code Online (Sandbox Code Playgroud)