Wait/notify, await/signal, faster blockingqueue that scales with N threads

Hi,
I have been benchmarking a blockingqueue. It holds 100 items before writers block. It uses not-empty/not-full semaphores. Typical stuff.
I have noticed that with 1 writer and 1 reader threads, using synchronized()+wait/notify is faster than reentrantlock+await/signal.
I tried to find the point (in number of W/R threads) where reentrant lock is better.
For the remainder os the discussion, I must say that I never use 'fair' rentrantlocks: I tested them and they are always slower than synchronized.
So, I always use 'unfair' locks.
The thing is, the tests results are messed up. I mean I would expect a monotonous progression in reentrant lock performance as the number of W/R threads is increasing. But the reality (on a dual core dual opteron) shows strange progressions. Without diving into numbers...
I would like to hear about the experiences of other people relatively to:
-queue implementations and readers semaphore, writers semaphores most efficient patterns.
-scalability observations and implementation choices related to the number of threads to be concurrent.
Of course I have been experimenting with notify()/signal() instead of notifyAll()/signalAll() in order to avoid waking up too many writers/readers that do not stand a chance to perform their enqueue/dequeue without going back to wait()/await() again (in my case, fairness isn't an issue for readers, and for the moment, I accept unfair enqueue from writers). Also, a reader can notify/signal not only a waiting writer but another waiting reader if the queue isn't empty after its own dequeue. I'm about to do the dual notify/signal for writers: not only notify/signal a waiting reader but also another waiting writer if the queue isn't full after its own enqueue.
Of course, this good-intentions implementation ends up notifying/signaling a lot. I'm searching for a new way of thinking, in case I have been blinded by too much obsession on my current implementation...! :-)
Thanks.
PS: for those of you that wonders why I don't use j.u.c array blocking queue, that's because I need:
a) many queues enqueue to be able to notify/signal a single thread (1 thread waiting to read many queues). This implies an externally plugged-in readers (not-empty) semaphore.
b) enqueueMany(array), dequeueMany(int max) ->array

In Java 5 ReentrantLock provides much better performance under contention than built-in sync. Conversely built-in uncontended sync is always much faster. In Java 6 contended built-in sync has pulled back some ground on ReentrantLock. So with only two threads it is not surprising that built-in sync is faster.
So the switch over point depends on the level of contention. This is a function of the number of threads (and CPU's) and what they do while holding the lock and between holding the lock.
For evaluating read/write synchronization you need to have a read operation that is relatively long to dominate the cost the heavier read-lock. You also need sufficient parallelism to allow enough concurrent readers to make overall reader "throughput" significant.
Benchmarks are seldom that useful/insightful unless realistic access patterns and workloads are used.

Similar Messages

  • Swf files that scale with the browser

    I uploaded a swf file with dreamweaver as a stand alone window and it works fine.  How do I get the swf file to scale larger or smaller as the user adjusts their browser window larger and smaller?  I would like to get the swf file to scale along with the browser window.  I posted this in dreamweaver but was told this is an action script issue.

    I found a simple solution, and I believe it is what you are looking for.
    1. In Flash, go to File>Publish Settings
    2. Click on the HTML Tab
    3. Where is says Dimensions, select Percent
    4. Though it is probably default, make sure the width and height are both set to 100.
    5. Click ok then go to File>Publish
    Now your movie should scale with the browser window.
    If you do not have Flash, then you can simple work with this sample code below:
    <object width="100%" height="100%" id="xyz" align="middle">
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="allowFullScreen" value="false" />
        <param name="movie" value="xyz.swf" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#ffffff" />
        <embed src="xyz.swf" quality="high" bgcolor="#ffffff" width="100%" height="100%" name="xyz"
        align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash"
        pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </object>
    Notice how width and height are set to "100%"? That's all you need.

  • A SIP trunking connection that scales with growth

    Since delivering its first inflight Internet experience in 2008, Gogo has grown to over 800 employees in five offices around the country. With 1000s of customers thirsty for in air data connections, its crucial that Gogo is highly available to support its staff and its airline partners globally. Capacity was near its max, but the […]
    Read More
    This topic first appeared in the Spiceworks Community

    Hi,
    No as you said you have already created the Trunk between the Sonus and Lync you can use the same trunk. but in the Sonus you have to configure the outbound routes from which Trunk you have to send the calls for the new Trunk provider or the Level3.
    check this
    https://support.sonus.net/display/UXDOC41/SIP+Trunking+Between+SIP+Border+Elements
    Whenever you see a helpful reply, click on Vote As Helpful & click on Mark As Answer if a post answers your question.

  • Simulating the wait/notify concept that Java has.

    Hi all,
    I need to simulate the wait/notify concept that Java has.
    My question is how do I get a Stored Procedure to wait (for a certain time period, once it times out the Stored Procedure can carry on but in an error state.) - (Like the "wait" in Java)
    And then another Stored Procedure to break this waiting state. (Like the "notify" Java).
    When the second stored procedure breaks the waiting state, the first stored procedure can carry on with it thread of execution.
    I have tried to use DBMS_Locks, but uncovered a few hiccups.
    Is there anything else I can try? ...
    Regards,
    Hilton

    Hi John,
    Thanks for the input, I have tried the using DBMS_Pipe and seems to have solved by problem.
    Will look into the DBMS_Alert as well.
    Thanks Again
    Hilton

  • Why do we need to take a lock before invoking wait()/notify() on an Objec

    Hi,
    Why do we need to take a lock before invoking wait()/notify() on an Object? i know that we shud take otherwise illegalstateexception is thrown.
    what is the reason to take a lock bfefore invoking the above methods. why does jvm expects from the programmer?
    Cheers,
    duggana.

    Well, very often a wait or notify is conditional on the state of some flag (semaphore) which is protected by the monitor. By putting the wait in a synchronized section you guarantee that the sempaphore won't change between the final test of it and the actual wait or notify, otherwise a notify might be lost and the program hang.
    // wait on semaphor
    if (!canProcede)
       synchronized(this)
           if(!canProcede)
              wait();
    //   release semaphor
    synchronized(this)
         if(!canProceed) {
              canProede = true;
              notify();
        }If the wait above wasn't guarded by the sychrozined it's possible the second code fragment might be executed between the test and the wait, in which case the wait would be called after the notify and, hence, wait for ever.

  • Why do we need to take a lock before invoking wait()/notify() on an Object?

    Hi,
    Why do we need to take a lock before invoking wait()/notify() on an Object? i know that we shud take otherwise illegalstateexception is thrown.
    what is the reason to take a lock bfefore invoking the above methods. why does jvm expects from the programmer?

    Please do not crosspost..

  • Sleep or wait() / notify()  Which is better IYO

    Consider an app where a central object, like an information server is handed a query and an amount of time will pass before that information is available. For caching, many objects may ask the same question and be waiting on the same answer. Is it better to have the queries do a sleep loop to wait for the response or is it better for the queries to register with the server and call a wait(), then have the server issue a notify to objects that were waiting?
    Thanks for the advice.

    Thank you. I like sleep as well. Although with three little ones that can be a difficulty.
    I am having a difficulty with how to implement the wait notify. Can you tell me if the following is a good / bad / normal / horribly wrong example?
    // sorta code...
    // This class goes to a central location
    // or the network for an answer.  It represents one answer for one query.
    class InfoServerQuery extends Thread{
      volatile boolean isComplete = false;
      volatile String response = null;
      Vector pool = new Vector();
      public synchronized boolean isReady(Object obj){
        if(!isComplete){
          // Add object to answer pool
          pool.add(obj);
          return false;
        }else{
          return true;
      public void run(){
        try{
          // Get the information.......
          response = getInfo();
          // set isComplete
          isComplete = true;
          // notify all that are waiting.
          for(int a = 0; a < pool.size(); a++)
          synchronized(pool.get(a)){pool.get(a).notify();};
        }catch(Exception e){
          throw new RuntimeException();
    // This class asks the questions.
    class QueryClient{
      // instantiated in constructor
      InfoServerQuery q;
      public String getAnswer() throws Exception{
        while(!q.isReady(this)) synchronized(this){wait();};
        return q.response;
    }Thanks for any insights.

  • Need help : wait() & notify()

    Hi, I am working on a project which has multiple components. Components support basic commands like startComponent, stopComponent, suspendComponent & resumeComponent. I am using jmx mgmt interface to call start, stop, suspend & resume commands. I am also using timer task in my components. My component start purgeTimerTask during startComponent call.
    I want purgeTimerTask to wait when my component is suspended & purgeTimerTask should be notify() when my component get resumed.
    Following is the implementation of suspendComponent() method.
    public void suspendComponent()
            try
                if (null != purgeTimerTask)
                    synchronized (purgeTimerTask)
                           purgeTimerTask.wait();
            catch (InterruptedException e)
                logError("PurgeComponent.suspendComponent() - exception: " + e);
        }Calling suspendComponent() method from JMX mgmt interface, control is not coming out of suspendComponent() method.
    I am not able to understand what is the cause of not coming out of suspendComponent() method.
    I have implemented resumeComponent() method where i am calling purgeTimerTask.notify() to reactivate the timer task.
    Can any one guide me here how can i resolve this issue?
    Thanks & regards,
    Pawan Modi

    PawanModi wrote:
    Hi, Ok you are right. After debugging i found that my current (application) thread is waiting at following statement.
    purgerTimerTask.wait();And not coming out of this statement.
    It won't come out until some other thread calls purgerTimerTask.notify().
    But this isn't a safe way to use wait and notify. You should do something like this:
    [code[
    synchronized(someMonitor) {
    while(suspended) {
    someMontitor.wait();
    And resume like:
    synchronized(someMonitor) {
        suspended = false;
        someMonitor.notifyAll();
    }

  • Trying to wrap my head around synchronized, wait, notify

    Hi There,
    I've been researching on how to make my midlet repeat cpu-intensive tasks for long periods of time. I found that if I put the big jobs in separate threads, that works fine. However, I'm at a point now where I need my "worker threads" to be able to do a big job, check to see if they need to keep going, then repeat. It seems that synchronized, wait, and notify are the way to do that. But I'm new to this concept.
    Apparently you can only use synchronized to create a spinlock between objects. So I guess that I need to define a new class, that starts its own thread, and has a method inside that thread that is synchronized?
    If that is true, then can my midlet call notify() on that? How does my midlet become a monitor?
    What does notify really do? Does it make the thread synch up state with the midlet globals? How can I get updated information to the thread?
    These things will help me get started.
    Thanks,
    theotherldso

    I answered my own question. I solved the problem by creating my own runnable class with some methods to control the thread. It works great, it's kind of like having my own main() that is controlled from my midlet.

  • I am using Vodafone at Delhi India with my Iphone 5S, 3g is activated with my number but i am not getting 3G signals iphone is also activated with vodafone but still waiting for 3G signals contacted vodafone but wasted my time pls help using APN www

    I am using Vodafone at Delhi India with my Iphone 5S, 3g is activated with my number but i am not getting 3G signals iphone is also activated with vodafone but still waiting for 3G signals contacted vodafone but wasted my time pls help using APN www

    Keep on talking to Vodafone and keep pestering them until you get a satisfactory answer.  Whether you get a 3G signal or not, is entirely the responsibility of Vodafone India because they are your carrier/phone company and nobody here can help you with that on a public user to user technical support forum.
    Contact Vodafone as they are the only ones who can help you.

  • My apps wont update! App store says I have 20 updates, when I click update all, they all go in to "Waiting" mode and its been like that for 24 hours now with no sign of updating. Do I have to delete them all and reinstall ?

    I updated my iOS system 2 Days ago. App store says I have 20 updates, when I click update all, they all go in to "Waiting" mode and its been like that for 24 hours now with no sign of updating. Do I have to delete them all and reinstall ? any help much apreciated.

    Snafujafo wrote:
    Dear ED3K:
        First:  I hope you don't work for Apple as you have some poor communication skills in assistance. That said, I would never in a million years pay you 45 dollars to help me. I think I would sleep with Satan first!!
    No one here works for Apple. This is a user-to-user technical support forum. Everyone here is a volunteer. You tend to get from this forum what you bring to it. If you come in ranting and raving and saying you're going to throw your iPhone out the window and that Apple is mean, people are not likely to respond to you with sweetness and light and puppies and kittens.
    If you really want help, I'd suggest you take a deep breath and then start a new thread in which you explain the problems you're having, the steps you've taken to resolve the problems, any error messages you've gotten. Stick to the facts. Check the attitude and emotion at the door. People will do their best to help you.
    Best of luck.

  • My TV is mounted on a wall so I can't connect the Apple TV device. Is it possible to connect to an HD Cable Box and send signal to TV that way? Other problem is that Box only has one HDMI socket .. Help!

    My TV is mounted on a wall so I can't connect the Apple TV device. Is it possible to connect to an HD Cable Box and send signal to TV that way? Other problem is that Box only has one HDMI socket so would also have to use a splitter. Tried Apple Support but couldn't offer a solution. I can't be the only person with this issue surely?
    Help!

    No, unless you are using a home theatre system already, your only option is to connect to the TV.

  • Page that scales down

    Even though I haven't yet uploaded these pages I'm working on, when I preview (in Firefox, for instance) my index page scales down in comparison to the others and yet they are all copies of each other to which I have still to change the content...I have tried to overwrite this index page (the one that scales down) with one of the others but that didn't work either; everytime I click the link "home" I get I slight shrink of the view in the browser.
    Can somebody please tell me what's wrong with it?
    Thanks a lot
    JV

    Hi
    Try giving your page a min-height of 100% in your css. This will at least make sure it is the size of the browser window. However your 'content' will still place the divs in the same position unless you give your footer a top-margin. there is a way to always have the footer at the bottom of the page.
    e.g.
    CSS -
    #fixedFooter {
      background-color: #000;
      color: #fff;
      height: 16px;
      padding: 10px 10px 10px 10px; /* Sets the padding properties for an element using shorthand notation (top, right, bottom, left) */
    /* The following code is for the fixed footer */
    html, body {
      height: 100%;
    #outerWrapper {
      min-height: 100%;
      position: relative;
    * html #outerWrapper {
      height: 100%;
    #fixedFooterWrapper {
      bottom: 0;
      position: absolute;
      width: 100%;
    HTML-
    <div id="fixedFooterWrapper"><div id="fixedFooter">Fixed Footer</div></div>
    PZ

  • TS4062 I cannot get a WiFi signal, which means that I cannot access all of the other features on my ipod. Is there anyway I can access all of the other features without Siri or WiFi?

    I cannot get a WiFi signal, which means that I cannot access all of the other features on my ipod. Is there anyway I can access all of the other features without Siri or WiFi?

    Hi. The two user tips both describe a sequence of steps that should get your library from the point where it threatens to wipe data from your device to where it is syncing normally, while recovering as much information as possible. It may still be necessary to wipe and reload the device but this should only take place once all the data that can be recovered has been recovered.
    Doing step 1 of 8 and then complaining things aren't the way you want them to be yet strikes me as premature...
    Since you appear to have all your media content, and we are discussing an iPod classic, not an iOS device, the main worries are already taken care of. What's left is ratings, playcounts, playlist membership and checked status. Since your device holds only part of your library at best you could only recover the missing data for the content that is on the device using third party tools.
    Recreating the previous checked/unchecked status of every track in your library from where you are now may not be that easy. Syncing with selected playlists has many advantages, one of which would have been that you would have a named playlist that could have been retrieved by 3rd party software if you had used this method.
    You haven't explained what caused your problem in the first place, but if you have a Previous iTunes Libraries folder holding old copies of your iTunes database (generated with each iTunes update) then it would be possible to restore the most recent of these and then update the library with any changes in your media folder.
    BTW Apple doesn't offer free support for this kind of issue with iTunes.
    tt2

  • HT204266 I want to buy the Craigslist pro app and when I sign into iTItem as described and fast shipping! Aunes with my Apple ID  and password ( both of which I know) it then asks security questions that I never chose ( or are even options to chose) in my

    I want to buy the Craigslist pro app and when I sign into iTItem as described and fast shipping! Aunes with my Apple ID  and password ( both of which I know) it then asks security questions that I never chose ( or are even options to chose) in my profile.

    If you don't know their answers then if you have a rescue email address (which is not the same thing as an alternate email address) set up on your account then the steps half-way down this page should let you reset them : http://support.apple.com/kb/HT5312
    If you don't have a rescue email address (you won't be able to add one until you can answer 2 of your questions) then you will need to contact iTunes Support / Apple to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset (and if you don't already have a rescue email address) you can then use the steps half-way down the HT5312 link above to add a rescue email address for potential future use

Maybe you are looking for

  • Page protection not work for smart form

    I want to my item data in the same page. ex: item no.  material   description   quantity              10   0000001  material CH  10                                   material EN                                   long text 1                           

  • Best way to deal with different screen sizes

    Hi ! We have been a small company using java for our client ( http://www.topbridge.com ) . The Swing client has used panels with absolute positions so the client would fit in 800x600 screen. Since java is 'run everywhere' we would like to rewrite it

  • HT204312 I-tunes taking my money and not giving me the song i wanted?

    I downloaded a song off the store and it didn't download until the 3rd time. It took 2.58 of mine without downloading the song. How can i get the 2.58 back onto my account? The song was Smalltown boy by BronskiBeat.

  • If technical system type is Exchange Infrastructure.

    Hi, In sld,when my technical system type is Exchange Infrastructure,there are 3 elements:adapter engine ,domain and integration server.But i know the right result is 6 elements,so other 3 elements are:integration repositary ,integration directory and

  • Ext. Drive issues/ invalid node structure

    I am running a few Lacie 500GB drives and one of them has gone kapoo. it will not mount and says it has no volume OSX can read, in Disk utility it shows up but after first aid verify it says the underlining task reported failure on exit (-9972) and a