I forked netlify functions repo and added my own code (this is my additional code). I also deployed the code onto Netlify. The test is located at the bottom of the Netlify page. In short, I added 2 Netlify Functions
-
Original: Uses ytdl-core and collect youtube video info, based on the VideoID obtained in the query parameter (e.g. .netlify/functions/youtube?videoID=UVV80kTudSM)
-
Modded: Exactly the same API as the one above, with addition JSON post-processing
Test Case 1:
- Call modded API, with the parameter UVV80kTudSM, and run it multiple times (browser refresh). The API fails half of the time.
Here is the attach the Netlify Function log, after calling the API multiple times:
8:30:33 AM: Duration: 7.92 ms Memory Usage: 96 MB
8:30:36 AM: Duration: 721.67 ms Memory Usage: 96 MB
8:30:39 AM: Duration: 10.96 ms Memory Usage: 96 MB
8:31:33 AM: Duration: 641.21 ms Memory Usage: 96 MB
8:31:36 AM: Duration: 4.93 ms Memory Usage: 96 MB
8:31:46 AM: Duration: 697.44 ms Memory Usage: 96 MB
The long-short-long-short API duration actually synced with the pass/fail situation. It seems to me that the reason of the short duration is because the Netlify function is not being executed fully.
Test Case 2:
- Run the Modded API, with parameter UVV80kTudSM
- Run the Modded API, with parameter DylgPyQxDiI
- Loop through Step 1 and Step 2
When I run the above sequence, the Youtube (Full) API works fine. The API doesn’t work fine only when the same API (with the same parameter) is being called again. Therefore I am not sure if the problem comes from my code or the behavior (caching?) of the Netlify function.
Thanks again for your time.