Skip to content

Handle I/O on background thread#106

Merged
wch merged 83 commits into
masterfrom
background-thread
Feb 16, 2018
Merged

Handle I/O on background thread#106
wch merged 83 commits into
masterfrom
background-thread

Conversation

@wch

@wch wch commented Jan 18, 2018

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread src/httprequest.h
// deletion of HttpRequest objects happens on the background thread, and so
// the lifetime of the Environment can't be strictly tied to the lifetime of
// the HttpRequest.
boost::shared_ptr<Rcpp::Environment> _env;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use a shared_ptr here how can you ensure that the environment won't be deleted on the background thread? I'm not sure what the best practice is here but I suspect it might be a naked pointer after all.

@wch wch Jan 22, 2018

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the implementation, there's a deleter function that ensures that the deletion happens on the main thread:
https://github.com/rstudio/httpuv/blob/3baaf620/src/httprequest.cpp#L146-L154
https://github.com/rstudio/httpuv/blob/3baaf620/src/auto_deleter.h#L13-L36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice!

Comment thread src/httprequest.h Outdated

void trace(const std::string& msg);
// TODO: Need a simpler, more robust construct for this
int _ref_count;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this obsolete? Doesn't seem to be read anywhere.

Comment thread src/httprequest.cpp

_handling_request = true;
_headers.clear();
_response_scheduled = false;

@jcheng5 jcheng5 Jan 22, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_bytesRead = 0;? Or remove _bytesRead if we don't need it.

wch added 2 commits January 22, 2018 13:21
I'm currently unsure whether the new ~Socket code is safe, or if there should be a deleter function added to the shared_ptr.
Comment thread src/httprequest.h
// kept going and scheduled another call into the main thread to send a
// response.
void responseScheduled();
bool isResponseScheduled();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really understand this--I'd like to talk about this and whether there are any race conditions (no mutexes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I get it now. :)

Comment thread src/callback.h

// If the Callback class were integrated into later, this wouldn't be
// necessary -- later could accept a void(Callback*) function.
void invoke_callback(void* data);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a convenience function that takes a boost::function<void(void)> and invokes later for you. Lots of the code in httprequest.cpp seems to follow the same pattern and would be easier to read if it was just invoke_later(boost::bind(&method, shared_from_this(), args...)).

@wch wch force-pushed the background-thread branch from 508ba1a to ff24146 Compare January 25, 2018 04:06
@wch wch force-pushed the background-thread branch from ff24146 to 23a53f9 Compare January 25, 2018 05:42
@wch

wch commented Feb 9, 2018

Copy link
Copy Markdown
Collaborator Author

Things to do before merging:

  • Run with shinyloadtest
  • automated load testing in Travis

@wch wch force-pushed the background-thread branch from 5b28149 to e676c32 Compare February 12, 2018 18:10
@wch wch merged commit 5d1b7ef into master Feb 16, 2018
@wch wch deleted the background-thread branch February 16, 2018 15:34
yihui added a commit to yihui/servr that referenced this pull request Apr 20, 2018
), so the `daemon` option in servr is no longer meaningful -- the server will always be daemonized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants