Christian Klemm
Christian Klemm

Reputation: 1505

MD5 generation overheat - Web API

To make it short and firm:

I have an api which returns a md5 of a specific file. The files are about 50 - 100 MB large. Now my question is:

What would need less resources/is stylistic better:

  1. Generating the md5 of the file for every GET
  2. Generating the md5 the first time a GET asks for it and the watch the file with a FileSystemWatcher for changes and refresh the md5 if the file changes

It was told me that generating a md5 many times could produce a overheat.

Upvotes: 0

Views: 358

Answers (2)

aaaa bbbb
aaaa bbbb

Reputation: 3043

The best approach is to compute the MD5 beforehand, and save the MD5 along with the main file.

Computing it dynamically on the first call adds complexity and processing time that can easily be avoided.

Upvotes: 0

Marco Scabbiolo
Marco Scabbiolo

Reputation: 7459

Second option will always be faster, how significantly depends on how often the file changes.

The most processing consuming operation you have is the MD5 hashing. If you have no choice but to hash the file with MD5, you should do all you can to reduce the number of times you do it. The ideal scenario would be to do it only once, which is exactly what would be doing with option 2.

That's supposing the file won't change, but definitely the chances to produce an overheat should be much lower than option 1, even if you change the file once every 5 minutes.

Upvotes: 2

Related Questions