I have a requirement to call REST API and implement different actions based on response times. For example, if the response is less than 30 secs - do process A, if between 31 - 60 seconds - do process B and timeout after 60 seconds. Is there any sample code to implement this in Quarkus/Mutiny? Any help is appreciated.
It is hard to provide some code since your question does not provide any details. It is because there are various libraries and solutions that you can use.
In general, I find it helpful to use a simple time diff method. This applies regardless of whether the code is implemented synchronously or asynchronously. The overall progress will be something like this:
Create a variable that stores the timestamp just before sending an HTTP request
Send the HTTP request
Retrieve the response and create a new timestamp, then compare it with the previous time.
When you compare these two timestamps you have the pending time between the request initiation and the resolution of its response.
By the way, If you have some base code that you desire to extend to achieve this functionality, please add it to the question and I might be able to edit it and show how the code may generally look like.
Related
Im trying to implement a lightweight SMB2 server on a very low resource system (no dynamic memory allocation). The system also only allows me to iterate directory contents so I have no idea the total file count etc. In response to a QUERY_DIRECTORY request, I think I have 2 options
1.) Enumerate the directory twice, firstly to calculate the total length of the response and the second time stream the results back
2.) My hope is that I can use compounded responses and return a response for each file using the NEXT_COMMAND field to indicate it is compounded however it isnt clear to me that the spec allows for this sort of behaviour or whether the compound response is ONLY to allow 2 seperate requests to be answered in one response.
My real goal is to implement a minimal functionality to be compatible with vanilla windows explorer to list/read and write files without too many bells and wistles
I'm currently testing a asp.net application. I have recorded all the steps i need and i have noticed that if i remove some of the parameters that i'm sending with the request the scripts still work and the desired outcome still happens. Anyway i couldn't find difference in the response time with them or without them, and i was wondering can i remove those parameters which are not needed and is this going to impact the performance in any way? I understand that the most realistic way of executing the scripts should be to do it like a normal user does (send all which is sent with normal usage) but this would really improve the readability of my scripts, any idea?
Thank you in advance and here is a picture which shows for example some parameters which i can remove and the scripts still work this is from a document management system and i'm performing step which doesn't direct the document as the parameters say but the normal usage records those :
Although it may be something very trivial like pre-populating date and time in calendar in user's time zone I believe you shouldn't be omitting any request parameters.
I strongly believe that load testing should mimic real user as close as possible so if it is not a big deal to send these extra parameters and perform their correlation - I would leave them.
Few other tips:
Embedded Resources (scripts, styles, images). Real-browsers download these entities so
Make sure you have "Retrieve All Embedded Resources" box checked
Make sure you "Use concurrent pool" size 3-5 threads
Filter out any "external" stuff via "URLs must match" input
Well-behaved browsers download embedded resources but do it only once. On subsequent requests they're being returned from browser's cache. Add HTTP Cache Manager to your Test Plan to simulate browser cache.
Add HTTP Cookie Manager to represent browser cookies and deal with cookie-based authentication.
See How To Make JMeter Behave More Like A Real Browser article for above tips explained just in case you want to dive into details
Less data to send, faster response time (normally).
Like you said, it's more realistic to test with all data from the recorded case, but if these parameters really doesn't impact your result and measured time, you can remove them for a better readability.
Sometimes jmeter records not necessary parameters because they are only needed for brower compability.
Is there any way to tell Fiddler not to log requests that have already been sent/logged previously?
Or even to filter them after you stop the capture, so as to get a smaller list to process?
Having a huge list of multiple identical requests is really difficult to debug...
Seemed simple but after many tries, i couldn't find anything.
Thanks in advance!
EDIT
To clarify things :
I am trying to debug a sort of monitoring system, in which the requests and responses change through time but could be hours and thousands of queries before an event changes the system state, hence the request response data. So i would like to skip logging identical request/response sets.
The easiest way to do this would be to write a bit of FiddlerScript (Rules > Customize Rules).
However, how exactly do you define "identical"? The same URL? The same request headers? The same response body? etc.
The definition you choose obviously has a significant impact on what the necessary FiddlerScript will look like.
I want to know if it's possible to get print something while Ajax is processing the Request.If yes then please let me know, Because i am facing one problem and i want to get to print something in between Ajax call request and it's response comes
actually i want to read csv of 3000+ rows and in between this process i want to display no of rows read and copied in another csv.
so i want to show something like process bar that out of 3000 there are 50 rows copies completely and this will continue process until it will reach to 3000 rows.
it there a way then let me know!
You can use XHR progress events (if your browser supports them):
https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress
https://dvcs.w3.org/hg/progress/raw-file/tip/Overview.html#interface-progressevent
How to check in JavaScript if XMLHttpRequest object supports W3C Progress Events?
But your question is more than simply I have 1000 bytes out of a possible 9999. You want to know exactly how many rows you have read up to that point.
I think you can read xhr.responseText on each progress event, but only if the request is parseable when incomplete (such as plain text), and also when not using an async request - https://stackoverflow.com/a/5319647/319878.
But for libraries like zip.js that use non-text binary data with arraybuffers when requesting zip content, this will not work, as these requests must be async (http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute). If you try to use xhr.responseText in this case, you will get an error like this (example from Firefox):
[Exception... "An attempt was made to use an object that is not, or is no longer, usable"
code: "11"
nsresult: "0x8053000b (InvalidStateError)"
location: "http://localhost/xhr-progress-test/test-xhr-on-progress.html Line: 1075"]
So for zipped content (using zip.js) I think you would have to wait for all of the response to arrive before using it. This is not what you want.
Much simpler would be to modify your server code to return a selection of rows at a time. E.g. rows 1-100, then 101-200, etc.
You may try one of multiple approaches to solve this problem:
JSONP Callback:
This is an apt solution for your problem. You may batch size your response to 50 rows of CSV data. Each JSONP call will have a start and will get 50 rows of data. So, to fetch 300 rows of data you'll have 6 callbacks. You may pass a start parameter and return start - start+49 rows (total 50) and when start == 1 you may pass the header too. On each successful callback you may increase the progress bar by a proportionate value.
Pros: Easy to show progress on no. of rows.
Cons: Data to return in the response has to be in JSON format; Need to implement callback function.
Calculating bytes:
Showing progress on no. of bytes transferred. One example is available on Stackoverflow. Not sure if it would apply in your case because you want to show progress on the basis of no. of rows.
Pros: Easy to show progress on no. of bytes.
Cons: May not apply in your case.
Loading icon or bar:
This is the easiest approach of all. Just show a loading image or a continuous progress bar which keeps on repeating.
Pros: Easy to show continuous progress.
Cons: Just shows the user that something is happening, nothing on percentage basis.
There could be other solutions too based on your situation, so please take this as a starting point and explore further.
I need to write a servlet that will return to the user a csv that holds some statistics.
I know how to return just the file, but how can I do it while showing a progress bar of the file creation process?
I am having trouble understanding how can I do something ajaxy to show the progress of the file creation, while creating the file at the same time - if I create a servlet that will return the completion percentage, how can it keep the same file it is creating while returning a response every x seconds to the browser to show the progress.
There's two fundamentally different approaches. One is true asynchronous delivery using an approach such as Comet. You can see some descriptions in articles such as this. I would use this approach where the data your are delivering is naturally incremental - for example live measurements from instrumentation. Some Java App Servers have nice integration between their JMS message systems and comet to the browser.
The other approach is that you have a polling mechanism. The JavaScript in the browser makes periodic calls to the server to get status (and maybe the next chunk of data). The advantage of this approach is that you are using a very standard programming model, less new stuff to learn. For many cases, such as "are there new answers for the Stack Overflow question I'm working on?" this is quite sufficient.
Your challenge may be to determine any useful progress information. How would you know how far through the generation of the CSV file you are?
If you are firing off a long running request from a servlet it's quite likely that you will effectivley spin off a worker thread to do that work. (Maybe using JMS, maybe using asynch workers) and immediately return a response to the browser saying "Understood, I'm thinking". This ensures that you are not vulnerable to and Http response timeouts. The problem then is how to determine the current progress. Unless the "worker" doing the work has some way to communicate its partial progress you have nothing useful to say. This kind of thing tend to be very application-specific. Some tasks very naturally have progress points (consider printing we know how many pages to do and how many printed) others don't (consider determining if a number is prime - yes or no, no useful intermediate stages perhaps)