Tag: chunking

我知道有关上传的内容,我们是否必须在接收端做一些事情?

我的azure函数接收大型video文件和图像,并将其存储在Azure blob中。 客户端API正在以块的forms将数据发送到我的Azure htttp触发器function。 我是否必须在接收端执行某些操作以提高性能,例如以块的forms接收数据? Bruce,实际上客户代码是由其他团队开发的。 现在我正在邮递员测试它并从多部分http请求中获取文件。 foreach (HttpContent ctnt in provider.Contents) { var dataStream = await ctnt.ReadAsStreamAsync(); if (ctnt.Headers.ContentDisposition.Name.Trim().Replace(“\””, “”) == “file”) { byte[] ImageBytes = ReadFully(dataStream); var fileName = WebUtility.UrlDecode(ctnt.Headers.ContentDisposition.FileName); } } ReadFullyfunction public static byte[] ReadFully(Stream input){ using (MemoryStream ms = new MemoryStream()) { input.CopyTo(ms); return ms.ToArray(); }}

使用Protobuf-net序列化分块字节数组的内存使用情况

在我们的应用程序中,我们有一些数据结构,其中包含一个分块的字节列表(当前公开为List )。 我们将字节大块化,因为如果我们允许将字节数组放在大对象堆上,那么随着时间的推移,我们会遇到内存碎片。 我们还开始使用Protobuf-net来序列化这些结构,使用我们自己生成的序列化DLL。 但是我们注意到Protobuf-net在序列化时会创建非常大的内存缓冲区。 浏览源代码时,似乎它可能无法刷新其内部缓冲区,直到整个List结构被写入,因为它需要在缓冲区前面写入总长度。 不幸的是,这首先解决了我们的工作,首先将字节分块,最终由于内存碎片而给我们OutOfMemoryExceptions(exception发生在Protobuf-net尝试将缓冲区扩展到84k以上时,这显然是在LOH,我们的整体进程内存使用率相当低。 如果我对Protobuf-net工作原理的分析是正确的,那么有没有解决这个问题的方法呢? 更新 根据Marc的回答,这是我尝试过的: [ProtoContract] [ProtoInclude(1, typeof(A), DataFormat = DataFormat.Group)] public class ABase { } [ProtoContract] public class A : ABase { [ProtoMember(1, DataFormat = DataFormat.Group)] public BB { get; set; } } [ProtoContract] public class B { [ProtoMember(1, DataFormat = DataFormat.Group)] public List Data { get; set; } […]