Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite MeasureManager in C++ #4885

Closed
jmarrec opened this issue May 12, 2023 · 2 comments · Fixed by #4920
Closed

Rewrite MeasureManager in C++ #4885

jmarrec opened this issue May 12, 2023 · 2 comments · Fixed by #4920

Comments

@jmarrec
Copy link
Collaborator

jmarrec commented May 12, 2023

Enhancement Request

Even in the labs subcommand, the MeasureManager is purely Ruby, so you can't use it to compute arguments for a Python Measure.

Detailed Description

void MeasureUpdateOptions::execute(MeasureUpdateOptions const& opt, ScriptEngineInstance& rubyEngine, ScriptEngineInstance& pythonEngine) {
opt.debug_print();
if (opt.server_port > 0) {
const auto measureManagerCmd = fmt::format(
R"ruby(
require 'measure_manager_server'
port = {}
server = WEBrick::HTTPServer.new(:Port => port)
server.mount "/", MeasureManagerServlet
trap("INT") {{
server.shutdown
}}
server.start)ruby",
opt.server_port);
rubyEngine->exec(measureManagerCmd);

Possible Implementation

We have the buildings blocks in place to compute arguments already in the MeasureUpdateCommand::getAndUpdateMeasure. But we'd need to write an HTTP server in C++. We have cpprestsdk that we already use for RemoteBCL. boost asio is another option, so is Poco.

@jmarrec
Copy link
Collaborator Author

jmarrec commented May 12, 2023

I scoped it out, implemented a basic http server with cpprestsdk, looks like it wouldn’t be a daunting task

@kbenne
Copy link
Contributor

kbenne commented May 12, 2023

I agree that a small http server using what we already have, cpprestsdk, is a good path.

@DavidGoldwasser DavidGoldwasser added this to the OpenStudio SDK 3.7.0 milestone May 18, 2023
kbenne added a commit that referenced this issue Aug 10, 2023
The MeasureManager server uses the cpprest SDK, which is an asynchronous
library that is implemented on top C++ threads. The challenge is that
API endpoints involving Ruby and Python are not thread safe. (This is
generally true for all conventional implementations of Ruby and Python,
not just OpenStudio's encapsulation of the scripting engines) The
solution implemented here, is to use a task queue so that all of the
"work" done by the API endpoints is done on the common main thread.

ref #4885
jmarrec added a commit that referenced this issue Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment