Tracking per-user requests

16 views
Skip to first unread message

BeeTimBee

unread,
Aug 10, 2022, 12:16:56 PM8/10/22
to openre...@googlegroups.com
Hello,

We use openresty as part of a file upload / download API. We use X-Accel-Redirect for downloads and we use lua for multipart and raw (PUT) uploads. Lua writes to disk, and POSTs the temp file name to our backend.

This works great. However, we want to limit the number of in-flight transfers by user. Since we run many openresty servers, we need a distributed way to track these concurrent transfers. We have written a simple api that allows us to POST when a transfer starts and DELETE when a transfer ends. So far, so good.

However, because of the use of X-Accel-Redirect for downloading, we use ngx.exec() to make our request to our backend (via an upstream) which serves the file. This gives no opportunity for making the DELETE request once the download is done. I looked at making this DELETE request in the log_by_lua phase, but it has very limited api access (no sockets, no coroutine access).

Basically, I want a coroutine that can detect when it's parent request is done and then issue the DELETE, or a timer that can do something similar.

The best solution I can come up with is that I can put some data into a shared dict at the beginning of a transfer, and remove that data at the end. Then a global timer could walk the shared dict and make all the POST and DELETE requests as necessary.

Is there a simpler solution?
Reply all
Reply to author
Forward
0 new messages