-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix some crasher bugs in DispatcherBucket.
- Fix wrong timeout calculation in DispatcherBucket. - Add a DummyRequestHandler, which is probably the fastest possible request handler implementation. This, together with DummySpawnManager, allows one to benchmark the Apache module's performance.
- Loading branch information
1 parent
456b4c1
commit a06160d
Showing
10 changed files
with
233 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "MessageChannel.h" | ||
#include "Utils.cpp" | ||
#include <vector> | ||
|
||
using namespace std; | ||
using namespace Passenger; | ||
|
||
static bool | ||
handleRequest(MessageChannel &reader, MessageChannel &writer) { | ||
vector<string> headers; | ||
|
||
P_TRACE("Reading request headers"); | ||
if (!reader.read(headers)) { | ||
return true; | ||
} | ||
P_TRACE("Done reading request headers"); | ||
|
||
string content("<b>Using C++ DummyRequestHandler</b><br>\n"); | ||
unsigned int i; | ||
for (i = 0; i < headers.size(); i += 2) { | ||
content += "<tt>"; | ||
content += headers[i]; | ||
content += " = "; | ||
content += headers[i + 1]; | ||
content += "</tt><br>\n"; | ||
} | ||
|
||
string header( | ||
"Status: 200 OK\r\n" | ||
"Content-Type: text/html\r\n" | ||
"Content-Length: " | ||
); | ||
header += toString(content.size()); | ||
header += "\r\n\r\n"; | ||
P_TRACE("Sending response header"); | ||
writer.writeScalar(header); | ||
P_TRACE("Sending response content"); | ||
writer.writeScalar(content); | ||
P_TRACE("All done"); | ||
writer.writeScalar("", 0); | ||
return false; | ||
} | ||
|
||
int | ||
main() { | ||
MessageChannel reader(STDIN_FILENO); | ||
MessageChannel writer(STDOUT_FILENO); | ||
bool done = false; | ||
initDebugging(); | ||
while (!done) { | ||
done = handleRequest(reader, writer); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CXX=g++ | ||
CXXFLAGS=-Wall -g -I../ext/apache2 `pkg-config --cflags apr-1` | ||
|
||
DummyRequestHandler: DummyRequestHandler.cpp ../ext/apache2/MessageChannel.h | ||
$(CXX) $(CXXFLAGS) -o DummyRequestHandler DummyRequestHandler.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#ifndef _PASSENGER_DUMMY_SPAWN_MANAGER_H_ | ||
#define _PASSENGER_DUMMY_SPAWN_MANAGER_H_ | ||
|
||
#define DUMMY_REQUEST_HANDLER_EXECUTABLE "/home/hongli/Projects/mod_rails/benchmark/DummyRequestHandler" | ||
|
||
#include <string> | ||
|
||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
|
||
#include "Application.h" | ||
|
||
namespace Passenger { | ||
|
||
using namespace std; | ||
|
||
/** | ||
* This class implements a dummy spawn manager. This spawn manager will spawn | ||
* benchmark/DummyRequestHandler, which is probably the fastest possible | ||
* implementation of a request handler. The purpose of this class to benchmark | ||
* the performance of the Apache module (i.e. not benchmarking the Ruby request | ||
* handler or Rails itself). | ||
* | ||
* This header file is not used by default. Modify ApplicationPool to make use | ||
* of this file/class. | ||
* | ||
* Of course, don't forget to compile benchmark/DummyRequestHandler before you | ||
* use this class! | ||
*/ | ||
class DummySpawnManager { | ||
public: | ||
ApplicationPtr spawn(const string &appRoot, const string &user = "", const string &group = "") { | ||
int fd1[2], fd2[2]; | ||
pid_t pid; | ||
|
||
pipe(fd1); | ||
pipe(fd2); | ||
pid = fork(); | ||
if (pid == 0) { | ||
pid = fork(); | ||
if (pid == 0) { | ||
dup2(fd1[0], 0); | ||
dup2(fd2[1], 1); | ||
close(fd1[0]); | ||
close(fd1[1]); | ||
close(fd2[0]); | ||
close(fd2[1]); | ||
execlp(DUMMY_REQUEST_HANDLER_EXECUTABLE, DUMMY_REQUEST_HANDLER_EXECUTABLE, NULL); | ||
_exit(1); | ||
} else { | ||
_exit(0); | ||
} | ||
} else { | ||
int reader, writer; | ||
|
||
close(fd1[0]); | ||
close(fd2[1]); | ||
reader = fd2[0]; | ||
writer = fd1[1]; | ||
waitpid(pid, NULL, 0); | ||
return ApplicationPtr(new Application(appRoot, pid, reader, writer)); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace Passenger | ||
|
||
#endif /* _PASSENGER_DUMMY_SPAWN_MANAGER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.