1nickt has asked for the wisdom of the Perl Monks concerning the following question:
Hi brethren, I am newly developing with Mojolicious. I have a question about scope. I've read some of the Mojo doc but not found a clear answer to my concern.
If I understand correctly, by default running a Mojo app under Hypnotoad will allow each worker process to accept N concurrent client connections, where N defaults to 1000 (from max_connections in Mojo::IOLoop). One can override this with the clients option, all the way down to 1 so that the worker process exits and a new one is spawned after each request. This is recommended only for applications that are heavily blocking.
What I haven't been able top confirm is whether each client connection is completely separate from the others within a single worker process. Here's the scenario:
- The application code instantiates an object for each HTTP request
- The object consumes a Logger role, which gets a logger from Log::Any and puts it in the object ($obj->log)
- The Log::Any logger object is global.
- The parent object sets some value in the $obj->log->context hash (see Log::Any context data)
- Another class that is not composed into the object gets the same logger and logs some message, which causes the same context data to be appended.
- Goal achieved -- log the tracking ID of an object instance even when not using the object's Logger role.
So what I want to make sure of is that the data stashed in the logger context hash is not shared, obviously. Do I need to set Hypnotoad so that only one client connection is handled per worker? Or is the scope limited to client connection already? Or, am I missing some fundamental Mojo concept?
Thanks!