What's the point of using Resque with Redis To Go for background tasks
If the point of having tasks like calling external services (such as sending emails) be sent to background tasks and workers to remove time consuming tasks from the main app, I don't understand why using Resque with Redis To Go is such a great idea. Isn't Redis To Go itself an external service in which case wouldn't that defeat the purpose since storing the key/values for the queue on Redis T开发者_如何学Pythono Go would be unpredictable and potentially time consuming itself?
Edit
The reason I'm confused is I hadn't set up any workers and the queue was generated (and obviously the operations were waiting because there were no workers) by Resque on Redis To Go. So I'm assuming it means that the initial Redis To Go write is done by the main thread.
The main reason to use background workers is so the main thread is not tied up with running the task. Using Resque, it allows tasks to be executed outside the main thread. This is good for many reasons. The biggest is that slow operations do not cause the main thread to hang, blocking out all functionality until the request is done.
Redis to Go is just a remote Redis database. In your main thread, you do an operation where you modify 500 keys. On a local database, that would take no time at all, but unless you use a multi command, you have to send each command to the server and wait for the response. Ok, no big deal if its a few commands, but it will take a noticeable amount of time to do that 500 times on a remote server. Here is some example numbers. It takes 5ms to do the operation locally. Here, using Resque is not needed, as the jobs are executed quickly and locally. Now, using Redis to Go, we have to go outside the LAN. Now, each operation takes 5ms (0.005 seconds). And if we were doing 500 of them, .005*500 is 2.5 seconds. Now, that is 2.5 seconds that are being used to query the database, and your main thread is locked until the requests are done. (Note, those numbers are totally random... They could be higher or lower)
Now, with Resque, those operations are done in the background. When your main thread executes, it will add the jobs to Resque. And the the main thread will execute. Resque will now execute the commands in the order they are received. Now, the execution might take 2.5 seconds, but those 2.5 seconds are not holding up the main thread.
精彩评论