Re: Running a function at fixed time intervals

Philip Aston <[email protected]>
Newsgroups gmane.comp.java.grinder.user
Message-ID <[email protected]>
On 22/11/13 07:02, [email protected] wrote:
> Hello,
> Here is what i am trying to achieve in Grinder:
>
> I have 1 agent, 1 worker, 50 threads. 
> I have a static dictionary that is common to all the threads. I want to
> update that dictionary every half an hour. Is there a way to do it. Any
> alternative way is also fine as long as i achieve the target.

You may need to provide more information. I'm guessing your worker
threads need to use the dictionary as a source of test data, or perhaps
to look up whether a response is valid, and that your half-hourly update
is the only thing that writes to the dictionary.

With a single process, its straightforward. You need to worry about
concurrent access to the dictionary when it is being updated. I'd do
something like this...

    from java.util.concurrent.atomic import AtomicReference

    # Atomic reference to hold a snapshot of the dictionary
    dictionary = AtomicReference({"a":1, "b":2})

    def update():
      newDictionary = .. read from file? ...
      dictionary.set(newDictionary)


    # reading from the dictionary

        a = dictionary.get()["a"]


Then use Python's threading.Timer, or Java's ScheduledThreadPoolExecutor
to run update() every 30 minutes.

- Phil

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk

_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.