Skip to content

Commit

Permalink
Make benchmark tool work
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrunbauer committed Sep 5, 2024
1 parent 1d96bc1 commit 14c33f9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
3 changes: 3 additions & 0 deletions adagucserverEC/CImageDataWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,9 @@ int CImageDataWriter::end() {
resetErrors();

printf("%s", resultHTML.c_str());

fflush(stdout);
fflush(stderr);
} /*End of text html */

/* Text XML */
Expand Down
4 changes: 4 additions & 0 deletions adagucserverEC/CRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ int CRequest::process_wms_getcap_request() {
;
if (status == CXMLGEN_FATAL_ERROR_OCCURED) return 1;
}

const char *pszADAGUCWriteToFile = getenv("ADAGUC_WRITETOFILE");
if (pszADAGUCWriteToFile != NULL) {
CReadFile::write(pszADAGUCWriteToFile, XMLdocument.c_str(), XMLdocument.length());
Expand All @@ -802,6 +803,9 @@ int CRequest::process_wms_getcap_request() {
printf("%s", XMLdocument.c_str());
}

fflush(stdout);
fflush(stderr);

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion adagucserverEC/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

// #define CImgWarpBilinear_DEBUG
// #define CImgWarpBilinear_TIME
#define MEASURETIME
// #define MEASURETIME

// #define CDATAREADER_DEBUG
// #define CCDFNETCDFIO_DEBUG
Expand Down
32 changes: 15 additions & 17 deletions adagucserverEC/adagucserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,16 @@ int _main(int argc, char **argv, char **) {
// setWarningFunction(serverWarningFunction);
// setDebugFunction(serverDebugFunction);

#ifdef MEASURETIME
// #ifdef MEASURETIME
StopWatch_Start();
#endif
// #endif

status = runRequest();
/* Display errors if any */
readyerror();
#ifdef MEASURETIME
// #ifdef MEASURETIME
StopWatch_Stop("Ready!!!");
#endif
// #endif

return getStatusCode();
}
Expand Down Expand Up @@ -476,20 +476,18 @@ void handle_client(int client_socket, int argc, char **argv, char **envp) {
char recv_buf[recv_buf_len];
memset(recv_buf, 0, recv_buf_len * sizeof(char));

char *cmd_query = "QUERY_STRING=";
int data_recv = recv(client_socket, recv_buf, recv_buf_len, 0);
if (data_recv > 0) {
if (strncmp(recv_buf, cmd_query, strlen(cmd_query)) == 0) {
dup2(client_socket, STDOUT_FILENO);
// dup2(client_socket, STDERR_FILENO);
dup2(client_socket, STDOUT_FILENO);
setenv("QUERY_STRING", recv_buf, 1);

CT::string cmd(recv_buf);
std::vector<CT::string> cmds = cmd.splitToStack("\"");
setenv("QUERY_STRING", cmds[1].c_str(), 1);
int status = do_work(argc, argv, envp);
// fprintf(stderr, "exiting, status=%d", status);

int status = do_work(argc, argv, envp);
exit(status);
}
fflush(stdout);
fflush(stderr);

exit(status);
}
}

Expand Down Expand Up @@ -521,7 +519,6 @@ int run_server(int argc, char **argv, char **envp) {

while (1) {
unsigned int sock_len = 0;
printf("Waiting for connection.... \n");

if ((client_socket = accept(listen_socket, (struct sockaddr *)&remote, &sock_len)) == -1) {
printf("Error on accept() call \n");
Expand All @@ -540,13 +537,14 @@ int run_server(int argc, char **argv, char **envp) {
}

int main(int argc, char **argv, char **envp) {
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering
setvbuf(stderr, NULL, _IONBF, 0); // turn off buffering

const char *ADAGUC_FORK = getenv("ADAGUC_FORK");
if (ADAGUC_FORK != NULL) {
int server_status = run_server(argc, argv, envp);
} else {
// normal flow without unix socket server/fork
return do_work(argc, argv, envp);
}

// setenv("QUERY_STRING", query_string.c_str());
}
36 changes: 27 additions & 9 deletions python/lib/adaguc/CGIRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,42 @@ async def run(self, cmds, url, output, env=[], path=None, isCGI=True, timeout=30
localenv["REQUEST_URI"] = "/myscriptname/" + path
localenv.update(env)

# print("# QUERY STRING:", url)
# print("# LOCAL ENV:", localenv)

# Execute adaguc-server binary
ON_POSIX = "posix" in sys.builtin_module_names
async with sem:
process_output = ""
# process_output = ""

client = socket.socket(socket.AF_UNIX)
client.connect("/tmp/adaguc.socket")
client.send(f"QUERY_STRING={url}".encode())
# client = socket.socket(socket.AF_UNIX)
# client.connect("/tmp/adaguc.socket")
# client.send(url.encode())

process_output = bytearray()
while data := client.recv(4096):
# print(data)
# while data := client.recv(4096):
# # print(data)
# process_output.extend(data)

# process_error = ""
# status = 0

# process_error = process_error.encode()

reader, writer = await asyncio.open_unix_connection("/tmp/adaguc.socket")
writer.write(url.encode())
await writer.drain()

while data := await reader.read(4096):
# print(f"Received: {data}")
process_output.extend(data)

process_error = ""
status = 0
print("Close the connection")
writer.close()
await writer.wait_closed()

process_error = process_error.encode()
status = 0
process_error = "".encode()

# process = await asyncio.create_subprocess_exec(
# *cmds,
Expand Down

0 comments on commit 14c33f9

Please sign in to comment.