简体   繁体   English

为什么REST API(Odata)更新这么重

[英]Why REST API (Odata) update is so heavy

really want to hear your opinion about data upload using Odata真的很想听听您对使用 Odata 上传数据的看法

I access REST API (Odata) that provides data about 350k rows (only 7 attributes).我访问 REST API(Odata),它提供了大约 350k 行的数据(只有 7 个属性)。 I am using Power BI to download this data.我正在使用 Power BI 下载此数据。 So when I am downloading the whole day set it downloads 67mb!因此,当我下载一整天时,它会下载 67mb!

Can someone explain to me why file with just 350k rows is so heavy?有人可以向我解释为什么只有 350k 行的文件这么重吗? ps when I am saving it in CSV it is just 3.7mb. ps 当我将它保存在 CSV 中时,它只有 3.7mb。

Lets do the math.让我们算一下。

67MB / 350K rows = 191 bytes per row. 67MB / 350K 行 = 每行 191 字节。

Each row will likely have at least a { , a } and a , , so that's 188 bytes per row.每行可能至少有一个{ , a }和一个, ,因此每行 188 个字节。

188 / 7 = around 27 bytes per attribute. 188 / 7 = 每个属性大约 27 个字节。 Each attribute probably also has at least 2 quotes ( " ), or 4 if they are all strings, and a : and , .每个属性可能还至少有 2 个引号 ( " ),如果它们都是字符串,则可能有 4 个引号,以及一个:,

So that leaves around 22 bytes for a property name and value.这样就为属性名称和值留下了大约 22 个字节。 That is also only true if you don't format your JSON with whitespace.仅当您不使用空格格式化 JSON 时,这也是正确的。 If you use whitespace for a prettier output a significant portion is going to be that whitespace.如果您将空格用于更漂亮的 output ,则很大一部分将是该空格。

22 bytes is not a ton of space for both of these. 22 字节对于这两者来说都不是很大的空间。 I assume that your rows will at least have a bunch of strings in there.我假设您的行中至少会有一堆字符串。 This paragraph for example is 162 bytes.这个段落例如是 162 字节。

CSV is going to be shorter because column names only appear once, and often there's only a comma between fields. CSV 会更短,因为列名只出现一次,而且字段之间通常只有一个逗号。 That's a significant drop in per-row overhead.这是每行开销的显着下降。

If you need this to be smaller, the first thing you should do is gzip your response.如果你需要这个更小,你应该做的第一件事是压缩你的响应。 Compression is going to be very effective if there's repetition.如果有重复,压缩将非常有效。

Or your API can just return CSV.或者您的 API 可以只返回 CSV。 There's no rule that says that everything has to be JSON.没有规定说一切都必须是 JSON。 Maybe in OData there is, but it's fine to make exceptions for outliers.也许在 OData 中有,但对异常值进行例外处理是可以的。

3.7 MB for your CSV seems too low, unless most of fields are empty. CSV 的 3.7 MB 似乎太低了,除非大多数字段都是空的。 If you have 7 fields per row, then there will be at least 6 commas and a "\r\n" line ending, so that only leaves 3 bytes for all your data.如果每行有 7 个字段,那么将至少有 6 个逗号和一个 "\r\n" 行结尾,因此您的所有数据只剩下 3 个字节。 Perhaps it's 37MB?也许是37MB?

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

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