question

Michael E Ortiz avatar image
Michael E Ortiz asked

How many bytes is in my User Data Request?

unity3d
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Michael E Ortiz avatar image Michael E Ortiz commented ·

More specifically, I am using Unity to send a Dictionary<string,string> data variable as a UpdateUserDataRequest. I am interested in knowing how many bytes this variable will be. I am just learning about metered pricing weighted by 1KB, so I am trying to optimize/limit my byte usage as this impacts the pricing. I have made some keys using JSON, so there are a good amount of fields in just one or two keys. Now I am thinking that may be an issue, because too much data is in one key and it "Costs" too much to update that key when only one or two fields are updated in that key. I am thinking I need to create more keys that have less information, so they "Cost" less to update since their byte size will be lower, is what I am now thinking.

0 Likes 0 ·
Michael E Ortiz avatar image
Michael E Ortiz answered

I've been researching this all day. Looks like the above example would be 65 bytes. The payloads sent to PlayFab will be encoded using UTF-8. As long as you stick to ASCII characters, each character in your key value will represent 1 byte. So all you have to do is add up all your characters to determine your payload size.

As far as pricing, each key that is read (or written) will be weighted to 1KB. If you are updating 1 key and the size of the key value is less than 1KB, then you will be billed 1KB or 1 "tic" anyway. However, if you are updating 1 key and the size of the key value is 2KB, then you will be billed 2 "tics". Basically, the minimum bill for a read or write is 1 tic for a single key value, though it can be much more if the key value is large. (A large key value of 50KB would be 50 tics for example to update, even if only 1 or 2 items/elements in it change). The current fee is 33 cents per 1 million tics for reads (or 7.15 dollars per million writes).

So it's probably not best to write several small sized key values at a high frequency since each key write would count as 1 tic, since the minimum is 1KB/1 tic. To minimize the cost in this scenario, it would be best to combine these small sized keys into one key via JSON. You may be able to do several key value updates for the price of 1 tic.

However, it is also not a good idea to update a very large sized key value frequently if there is just one or two items being updated in it. In my OP, I was reading a 10KB key value more frequently than I probably should have, and I saw my monthly reads balloon in my Billing summary, and I am the only person on my game at the moment.

Also, if your key value is getting large, it might be best to map various ASCII characters to represent different things to reduce your key value byte size. Avoid using natural language or words to represent things. I was able to reduce a 50KB key value to 1KB that way. You just have to get creative with you mapping to represent information.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Michael E Ortiz avatar image
Michael E Ortiz answered

For example, if I had a key called "Metals" and the key had this value: { "gold": "400", "silver": "100", "copper": "40", "iron": "100" }, how would I calculate it's byte size when I make a call to update this to PlayFab?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Michael E Ortiz avatar image Michael E Ortiz commented ·

The above example would be 65 bytes. The payloads sent to PlayFab will be encoded using UTF-8. As long as you stick to ASCII characters, each character in your key value will represent 1 byte. So all you have to do is add up all your characters to determine your payload size.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.