-
Notifications
You must be signed in to change notification settings - Fork 63
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
Very slow response #18
Comments
Any idea @sprinfall |
Because the file data is all cached in the memory. What is the size of your test file? |
its 10K image file . almost 1 second for each post very slow. There should be something that missed . Test yourself please |
I am posting with curl for test : curl -X POST "http://127.0.0.1:8000/predict/image" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "name=mmm" -F "file=@/Users/xxx/Charles_Bronson/Charles_Bronson_0003.jpg;type=image/jpg" |
@sprinfall Best |
@MyraBaba Please feel free to use. |
Ok I will test the new code . But you wll see the slowness of the response.. Something stalling / delaying. Best |
Hi, I use Python Requests library to post a JPG file, the 1s delay disappears. Just for your information. BTW, if you want to post large files, please consider to NOT use multipart form data. Please use a normal post with streaming instead. |
Hi @sprinfall My files mostly around 10K to 30K so small ones. What is the curl post and python post differences. ? Best |
import requests
url = 'http://127.0.0.1:8000/upload'
files = {'file': open('path/to/jpg', 'rb')}
r = requests.post(url, files=files)
print(r.text) |
@sprinfall can you test in aloop ? for i in range(100): gives error |
@MyraBaba Sorry, that issue was introduced by my last small optimization. I have reverted the change. |
@sprinfall any perf fix? |
I have two suggestions:
|
I will test right today and let you know. |
Hi @sprinfall I tested with :
Got errors:
|
I will look into it tonight. |
@MyraBaba I found that from the second request in the loop, the file data sent was empty. Please try to move the files definition into inside of the loop. Meanwhile, I made a quickfix to handle this empty form part data. Please pull the code. But I will do more test tomorrow. |
@sprinfall Hi again, I love the webcc its fantastic work. Thanks. Do you think that we can embed it to our Qt Project ? Do you Qt ? |
@sprinfall do you know Qt platform ? |
For signal/slot mechanism, you have to use QNetworkAccessManager: https://doc.qt.io/qt-5/qnetworkaccessmanager.html |
Hi,
I wrote the Qt forum but not have. Complete answer : https://forum.qt.io/topic/122927/c-rest-api-3rd-party-integration-question/8 <https://forum.qt.io/topic/122927/c-rest-api-3rd-party-integration-question/8>
BC
PS: QNetworkAccessManager is ok for doing REST SERVEr?
… On 21 Jan 2021, at 04:45, Chunting Gu ***@***.***> wrote:
@sprinfall <https://github.com/sprinfall> Hi again,
I love the webcc its fantastic work. Thanks.
Do you think that we can embed it to our Qt Project ? Do you Qt ?
It will be great if we get data as signal/slot mechanism
For signal/slot mechanism, you have to use QNetworkAccessManager: https://doc.qt.io/qt-5/qnetworkaccessmanager.html <https://doc.qt.io/qt-5/qnetworkaccessmanager.html>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#18 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEFRZH7ROCBGM6YMQ2QM273S26BM5ANCNFSM4UIFZJUQ>.
|
Hi,
I tried to use your server rest example in the Qt . Could find a way to integrate with signal slot ..
It is creating a new FileUploadView instance inside the Qt thread so can’t access the signal cut emit the received data to the main thread.
Yes I am a newbie c++ world. Most mathematician algorithm person . If you show me a sample ie one is suggested
"to pass the shared pointer to the start_Rest() function and therefore you can do the connection from where you call this function.”
BEst
#include "restapi.h"
#include <QDebug>
RestApi::RestApi(QObject *parent) : QObject(parent)
{
qDebug() << "xx restapi.cc REST API started " << endl;
}
void RestApi::start_Rest()
{
int PORT = 7000;
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
std::uint16_t port = static_cast<std::uint16_t>(PORT);
try {
webcc::Server server{ boost::asio::ip::tcp::v4(), port };
server.set_buffer_size(webcc::kBufferSize * 10);
server.Route("/upload", std::make_shared<RestApi>(), { "POST" });
server.Run();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
// return 1;
}
}
webcc::ResponsePtr RestApi::Handle(webcc::RequestPtr request)
{
if (request->method() == "POST") {
return Post(request);
}
return {};
}
webcc::ResponsePtr RestApi::Post(webcc::RequestPtr request)
{
emit test_signal ();
std::cout << "form parts: " << request->form_parts().size() << std::endl;
std::string resp ;
for (auto& part : request->form_parts()) {
std::cout << "name: " << part->name() << std::endl;
resp = part->name();
if (part->file_name().empty()) {
std::cout << "data: " << part->data() << std::endl;
} else {
size_t size=part->data().size();
if(true){
std::ofstream myFile ("/Users/tulpar/Projects/webcc-21Dec/build/webccData-QT"+ std::to_string (image_counter++) +".jpeg", std::ios::out | std::ios::binary);
myFile << part->data();
myFile.close ();
QByteArray byteArray(part->data().c_str(), part->data().length());
QPixmap img;
img.loadFromData (byteArray);
RestApi::sendPix (img);
}
// Save part->data() as binary to file.
// ...
}
}
return webcc::ResponseBuilder{}.Created().Body(" .. OK " + resp)();
}
void RestApi::sendPix(QPixmap &pix)
{
emit rest_image_received (pix);
}
… On 21 Jan 2021, at 04:45, Chunting Gu ***@***.***> wrote:
@sprinfall <https://github.com/sprinfall> Hi again,
I love the webcc its fantastic work. Thanks.
Do you think that we can embed it to our Qt Project ? Do you Qt ?
It will be great if we get data as signal/slot mechanism
For signal/slot mechanism, you have to use QNetworkAccessManager: https://doc.qt.io/qt-5/qnetworkaccessmanager.html <https://doc.qt.io/qt-5/qnetworkaccessmanager.html>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#18 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEFRZH7ROCBGM6YMQ2QM273S26BM5ANCNFSM4UIFZJUQ>.
|
|
Hi,
@sprinfall
Here a simple Thread example.
İf its work in Thread and result is usable via Qt signals very helpful for the community.
Best
[SimpleRestWebcc.zip](https://github.com/sprinfall/webcc/files/5850747/SimpleRestWebcc.zip)
… On 21 Jan 2021, at 14:48, Chunting Gu ***@***.***> wrote:
@MyraBaba <https://github.com/MyraBaba>
Run the REST server in a thread in your Qt application (see the server_states.cc example).
In RestApi (the View), emit signals of some global (or Singleton) QObject after the requests have been handled (in your case, images are uploaded).
In your Qt widgets, connect the signals of that global (or Singleton) object to some slots.
I will come back to you later.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#18 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEFRZHYCKTI5FCDLICC4YX3S3AIAPANCNFSM4UIFZJUQ>.
|
@MyraBaba |
@sprinfall Thanks a lot. I tested. Now I try to put same way to in my QTHREAD logic. Do you think it is also work in the QTHREAD created by the mainwindow ? Best |
@sprinfall Thanks a lot . what is the proper way to pass below objects which I can use inside the
the objects :
how can I do this to use also inside webcc::ResponsePtr Handle(webcc::RequestPtr request) override ? whenever I start to think I am something at c++ always hitting such a wall. Appreciate your help. I mentioned and advise your webcc in Qt forum. Best |
@MyraBaba You want to access Landmarker, Facenet and Aligner from the overridden Handle() method, right? |
I suggest to use C++ std::thread to run the HTTP server. QThread is quite a different thing. It has extra event loop? |
Hi,
I am testing example/form_server both my Mac Pro and also raspi4 . its super slower than the python (fastapi) ? almost 10 times slower
Why is this ? am I missed something ?
Best
The text was updated successfully, but these errors were encountered: