I want to download some information from url every 20 seconds and update view based on that info (2-3 labels change text values). I'm using AFNetworking for making request operations in my app.
Should I use NSTimer and make it call method with AFNetworking request every 20 seconds ? Or is there some better way to implement this ?
Thanks
You can use an NSTimer. There is a repeats parameters in the NSTimer scheduleWithTimeInterval to do repeating request.
Instead you can also define a method you can call every 20 seconds and in that method you can decide whether to make the request based on some logic(like a boolean) whether the previous request was successful or not. This can be useful, if there is a server problem and you continue requesting the server unnecessarily.
Related
I am using DirSync Control (Cookie) to get the latest changes using the below technique. Is it possible to get that result with pagination ?
https://learn.microsoft.com/en-us/windows/win32/ad/polling-for-changes-using-the-dirsync-control
Example: If 500 updates have happened, can i get updates from 1-50, or 51-100 (paging with skip) ?
The result returned is paginated. You need to put the cookie, returned from the previous response into the next request. However, from my experience the number of changes on every page may vary. You can set the upper border, but I would not recommend to rely on it. If you want to display/send changes in batches with predefined size additional processing should be done on the client side
I'm using SWR hook along with next.js for the first time and i've tried to get some answers about something but i couln't get them, not even with the docs.
Questions: So, i know SWR provides a cache with your data, and it updates in real time, but i'm kinda lost between two options that you have to use the hook. So, normally, you have dedupeInterval and refreshInterval
refreshInterval = 0: polling interval (disabled by default)
dedupingInterval = 2000: dedupe requests with the same key in this time span
Now, what are the differences between these two ? if i have two request with the same key, it will update after two seconds ? is it the same as refreshInterval ? if i use refreshInterval, would i have problems with performance ? since it's making a request in very short periods of time
If you can help me with this, it would be great !
Thanks for your time !!
Now, what are the differences between these two ?
The difference is that:
refreshInterval is defining a time after which a new request will be sent to update your data. eg. every second.
dedupeInterval is defining a time during which if a request was already sent for a specific data (ie. a data having a specific key), when rendering a component that asks for a new request to refresh that data, the refresh will not be done.
Deduplicating means eliminating duplicates, ie. making potentially less requests, not more. They give an example in their documentation with a component that renders 5 times another component called <Avatar /> that uses the swr hook. But the actual request will be made only once because that rendering will be within the default 2 seconds time span.
If i have two request with the same key, it will update after two seconds ? Is it the same as refreshInterval ?
No, the dedupeInterval set to 2 seconds will not automatically update the data. It will update it only if a component using the same key with the swr hook is rerendered after the 2 seconds. Or if you haven't deactivated other updating mechanisms like on focus and the user puts the focus on your component.
With refreshInterval there would be an API call every X amount of time, as long as the component is still mounted, even if it doesn't rerender and the user doesn't interact with it.
If i use refreshInterval, would I have problems with performance ? Since it's making a request in very short periods of time.
Yes, if the user opens your page and does nothing but reading content during 20 seconds, and you have set the refreshInterval to 1 second, there will be 20 API calls to update that data during that time. That behavior may be useful if your data changes every few seconds and you need to have the UI up to date. But clearly it can be a performance issue.
The reason why the refreshInterval is disabled by default whereas the dedupeInterval is set to 2 seconds is to avoid too many API calls.
In our angular application, we are implementing a timmer function and calling the one API until a particular value (balance amount) changes in API call with 10 seconds interval with the limit of 5 times.
After we implement the timer function. We absolved that instead of making API call every time. API call taking the value from the disk catch some times.
Can anyone suggest me what is the solution to make API call not take get the information form desk catch?
enter image description here
There are 2 things you can do. At server-side from API, pass no-cache header from HTTP response
Cache-Control: no-cache
OR you can also add timestamp to your API call URL. So that browser doesn't cache it. Something like this :
var url = "http://api.mydomain.com/some-end-point?v=" + (new Date()).getTime();
I have an app wherein i have a comments box. Everything is working fine. However there is a small thing that is bugging me. I am using React and set the update Interval to 2 sec. So every 2 sec, a REST call is made which will return a new comment or no comment (i do this by sending last updated timestamp in the API call). However this rest call, is still returning 200 B, when empty. now on its own this size is minimal. But if a user stays on the page for 10 minutes, even with no new comments, he would download 10*60/2*200 B ~ 60000 B ~ 60 KB.
Is this considered appropriate or should i look into other solutions?
I would use a websocket.
You can then poll your comments-source for changes from the server with no need to involve the browser. Only if you detect new comments on the server would you then broadcast an appropriate socket event with the payload. All listening clients would then update their comments only when required.
In this way you avoid any overhead, either the server load caused by creating and destroying the http connections, or client load receiving 'empty' payloads.
Apologies if this request is similar to others - I am new to JMeter and have searched for other relevants posts but couldn't find anything - or maybe I just didn't understand them!
I'm performance testing a system with a web based application. The front end system will be processing records submitted into the system via MQ - the front end allows the user to pick up a record from the queue, validate some detail, make changes and submit the changes.
There will be 20 users using the front end to do this message validation, update and submission.
Each user is expected to need 30 seconds to pick a message from queue, make changes and resubmit - so we are expecting 1 user to process 120 records/hour, so 20 users will be expected to process 2400 records/hour
The picking up the record off the queue, changing it and submitting the changes will be done via 3 individual web pages.
SO - think time across the 3 pages has been defined as 24 seconds (leaving 6 of the 30 second limit for rendering, server responses, db calls etc.)
However I don't know how to specify this within JMeter. From my reading I can see that I can add a Timer in as a parent to a sampler and I assume I can add a Timer in as a parent of the Recording Controller? - but I need to be able to specify that the 24 second think time is spread across those 3 different pages.
I read a post elsewhere suggesting that if I record using the proxy after adding the Gaussian Random Timer in as a child of the Test Plan (parent to everything else) then the http proxy will record the think time as a ${T} variable in the Gaussian Random Timer - I tried this and this didn't work (also I don't want to rely on this - I'd like to be able to understand and make changes to think time properly rather than relying on JMETER to do it for me.)
To reiterate - 20 users, 30 seconds for 1 user to complete a transaction, TT defined as 24 seconds - I am struggling what Timer to use, where to put it so that the think-time is spread across the samplers that equate to the GETS associated with the 3 pages the user will navigate through.
Apologies for the lengthy post - I just wanted to be clear and concise.
Many thanks in advance,
As per JMeter Timers documentation
Note that timers are processed before each sampler in the scope in which they are found; if there are several timers in the same scope, all the timers will be processed before each sampler.
Timers are only processed in conjunction with a sampler. A timer which is not in the same scope as a sampler will not be processed at all.
To apply a timer to a single sampler, add the timer as a child element of the sampler. The timer will be applied before the sampler is executed. To apply a timer after a sampler, either add it to the next sampler, or add it as the child of a Test Action Sampler.
Now regarding "what timer to use"
There are 2 scenarios:
Virtual-User-oriented scenario - when you try to simulate N users working together
Goal-Oriented-scenario - when you try to produce N hits per second load.
In case of scenario 1 even Constant Timer can be quite enough, besides it will provide repeatability of results. See above quote for information on where to put your timer(s)
In case of scenario 2 you'll need Constant Throughput Timer. If 20 users process 2400 records per hour and each record assumes 3 web page calls, it means that 7200 requests will be made in one hour which in its turn stands for 120 requests per minute (this is what you should enter into the timer's "throughput" area) or 2 requests per second.