IO delay causes buffered streams to hang

I'm writing an application that uses the network and in order to test under slow conditions I created custom input/output streams that just puts in a delay in the basic read() and write(int b) methods before calling the method for the stream passed in the constructor. This allows me to find problems where the interface hangs under slow conditions etc. very quickly.
The problem is that on buffered streams (I have specifically had trouble with BufferedReader and BufferedOutputStream) it causes the stream to just hang. It works fine without the stream with the delay but with it something is causing a hang. I think it may have something to do with the network because I don't have the problem with File IO. Does anybody know why a delay would cause a buffered stream to hang?

Well the I know the socket has not timed out. I usually set the delay about 1 to 3 milliseconds. This will happen everytime a read() or write(int b) occurs so it is enough to slow things down.
This is a code sample that shows the basic idea for reading in a file:
import java.io.*;
public class Example
static class SlowInputStream extends InputStream
private InputStream in;
public SlowInputStream(InputStream i)
in=i;
public int read() throws IOException
try { Thread.sleep(3); }
catch(InterruptedException e) {}
return in.read();
public static void main(String[] args)
throws IOException
if(args.length==0)
System.out.println("Need filename.");
System.exit(0);
SlowInputStream sis=new SlowInputStream(
new FileInputStream(args[0]));
BufferedReader in=new BufferedReader(
new InputStreamReader(sis));
String text;
StringBuffer temp=new StringBuffer();
while((text=in.readLine())!=null)
temp.append(text);
temp.append("\n");
System.out.println(temp.toString());
I would have posted a networking example but I create a subclass of PlainSocketImpl to so I can wrap all the streams networking streams and this requires to set the bootclasspath, but the above shows the basic technique.
Thanks

Similar Messages

  • WPF UI running in seperate runspace - able to set/get controls via synchronized hash table, but referencing the control via the hash table from within an event handler causes both runspaces to hang.

    I am trying to build a proof of concept where a WPF form is hosted in a seperate runspace and updates are handled from the primary shell/runspace. I have had some success thanks to a great article by Boe Prox, but I am having an issue I wanted to open up
    to see if anyone had a suggestion.
    My goals are as follows:
    1.) Set control properties from the primary runspace (Completed)
    2.) Get control properties from the primary runspace (Completed)
    3.) Respond to WPF form events in the UI runspace from the primary runspace (Kind of broken).
    I have the ability to read/write values to the form, but I am having difficulty with events. Specifically, I can fire and handle events, but the minute I try to reference the $SyncHash from within the event it appears to cause a blocking condition hanging both
    runspaces. As a result, I am unable to update the form based on an event being fired by a control.
    In the example below, the form is loaded and the following steps occur:
    1.) Update-Combobox is called and it populates the combobox with a list of service names and selects the first item.
    2.) update-textbox is called and sets the Text property of the textbox.
    3.) The Text value of the textbox is read by the function read-textbox and output using write-host.
    4.) An event handle is registered for the SelectionChanged event for the combobox to call the update-textbox function used earlier.
    5.) If you change the selection on the combobox, the shell and UI hangs as soon as $SyncHash is referenced. I suspect this is causing some sort of blocking condition from multiple threads trying to access the synchronized nature of the hash table, but I am
    unsure as to why / how to work around it. If you comment out the line "$SyncHash.TXT_Output.Dispatcher.Invoke("Send",[action]{$SyncHash.TXT_Output.Text = $Value})" within update-textbox the event handler will execute/complete.
    $UI_JobScript =
    try{
    Function New-Form ([XML]$XAML_Form){
    $XML_Node_Reader=(New-Object System.Xml.XmlNodeReader $XAML_Form)
    [Windows.Markup.XamlReader]::Load($XML_Node_Reader)
    try{
    Add-Type –AssemblyName PresentationFramework
    Add-Type –AssemblyName PresentationCore
    Add-Type –AssemblyName WindowsBase
    catch{
    Throw "Unable to load the requisite Windows Presentation Foundation assemblies. Please verify that the .NET Framework 3.5 Service Pack 1 or later is installed on this system."
    $Form = New-Form -XAML_Form $SyncHash.XAML_Form
    $SyncHash.Form = $Form
    $SyncHash.CMB_Services = $SyncHash.Form.FindName("CMB_Services")
    $SyncHash.TXT_Output = $SyncHash.Form.FindName("TXT_Output")
    $SyncHash.Form.ShowDialog() | Out-Null
    $SyncHash.Error = $Error
    catch{
    write-host $_.Exception.Message
    #End UI_JobScript
    #Begin Main
    add-type -AssemblyName WindowsBase
    [XML]$XAML_Form = @"
    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Window.Resources>
    <DataTemplate x:Key="DTMPL_Name">
    <TextBlock Text="{Binding Path=Name}" />
    </DataTemplate>
    </Window.Resources>
    <DockPanel LastChildFill="True">
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
    <Label Name="LBL_Services" Content="Services:" />
    <ComboBox Name="CMB_Services" ItemTemplate="{StaticResource DTMPL_Name}"/>
    </StackPanel>
    <TextBox Name="TXT_Output"/>
    </DockPanel>
    </Window>
    $SyncHash = [hashtable]::Synchronized(@{})
    $SyncHash.Add("XAML_Form",$XAML_Form)
    $SyncHash.Add("InitialScript", $InitialScript)
    $Normal = [System.Windows.Threading.DispatcherPriority]::Normal
    $UI_Runspace =[RunspaceFactory]::CreateRunspace()
    $UI_Runspace.ApartmentState = [System.Threading.ApartmentState]::STA
    $UI_Runspace.ThreadOptions = [System.Management.Automation.Runspaces.PSThreadOptions]::ReuseThread
    $UI_Runspace.Open()
    $UI_Runspace.SessionStateProxy.SetVariable("SyncHash",$SyncHash)
    $UI_Pipeline = [PowerShell]::Create()
    $UI_Pipeline.Runspace=$UI_Runspace
    $UI_Pipeline.AddScript($UI_JobScript) | out-Null
    $Job = $UI_Pipeline.BeginInvoke()
    $SyncHash.ServiceList = get-service | select name, status | Sort-Object -Property Name
    Function Update-Combobox{
    write-host "`nBegin Update-Combobox [$(get-date)]"
    $SyncHash.CMB_Services.Dispatcher.Invoke($Normal,[action]{$SyncHash.CMB_Services.ItemsSource = $SyncHash.ServiceList})
    $SyncHash.CMB_Services.Dispatcher.Invoke($Normal,[action]{$SyncHash.CMB_Services.SelectedIndex = 0})
    write-host "`End Update-Combobox [$(get-date)]"
    Function Update-Textbox([string]$Value){
    write-host "`nBegin Update-Textbox [$(get-date)]"
    $SyncHash.TXT_Output.Dispatcher.Invoke("Send",[action]{$SyncHash.TXT_Output.Text = $Value})
    write-host "End Update-Textbox [$(get-date)]"
    Function Read-Textbox(){
    write-host "`nBegin Read-Textbox [$(get-date)]"
    $SyncHash.TXT_Output.Dispatcher.Invoke($Normal,[action]{$Global:Return = $SyncHash.TXT_Output.Text})
    $Global:Return
    remove-variable -Name Return -scope Global
    write-host "End Read-Textbox [$(get-date)]"
    #Give the form some time to load in the other runspace
    $MaxWaitCycles = 5
    while (($SyncHash.Form.IsInitialized -eq $Null)-and ($MaxWaitCycles -gt 0)){
    Start-Sleep -Milliseconds 200
    $MaxWaitCycles--
    Update-ComboBox
    Update-Textbox -Value $("Initial Load: $(get-date)")
    Write-Host "Value Read From Textbox: $(Read-TextBox)"
    Register-ObjectEvent -InputObject $SyncHash.CMB_Services -EventName SelectionChanged -SourceIdentifier "CMB_Services.SelectionChanged" -action {Update-Textbox -Value $("From Selection Changed Event: $(get-date)")}

    Thanks again for the responses. This may not be possible, but I thought I would throw it out there. I appreciate your help in looking into this.
    To clarify the "Respond to control events in the main runspace"... I'm would like to have an event generated by a form object in the UI runspace (ex: combo box selectionchanged event) trigger a delegate within the main runspace and have that delegate in
    the main runspace update the form in the UI runspace.
    ex:
    1.) User changes selection on combo box generating form event
    2.) Event calls delegate (which I have gotten to work)
    3.) Delegate does some basic processing (works)
    4.) Delegate attempts to update form in UI runspace (hangs)
    As to the delegates / which runspace they are running in. I see the $synchash variable if I run get-var within a delegate, but I do not see the $Form variable so I am assuming that they are in the main runspace. Do you agree with that assumption?

  • I have an email account causes the machine to hang up after being in use for a day.  It only occurs on my Macbook Pro and only one particular account.  The problem account works fine on my iMac and Windows Machines.  Any ideas what is causing this?

    I have an email account causes the machine to hang up after being in use for a day.  It only occurs on my Macbook Pro and only one particular account.  The problem account works fine on my iMac and Windows Machines.  I have been to the local Genius bar and through trial and error we have determined that Mail is working ok but somehow the account is causing the problem.  I have used this account for years.  Any ideas what is causing this?

    No idea why, but one thing you may try if you have the time, is create a new user, and set up the problem mail account in the new user space. See if it causes your MBP to hang as well.  That will tell you if it is something wrong with your main User, or something wrong with MBP.
    Assuming this works, I'd nuke the problem account in your main user space, re-start, and reinititate the account and see if that helps.
    Depening on how many email accounts you have setup, it may be necessary to nuke the whole Mail folder in your User/Library....   Hard way to get it to work, but just my idea.

  • Whats the different between regular strems and buffered streams?

    Hum , Hey.
    Whats the different between regular streams(un buffered) and buffered streams?
    When should I use buffered streams and when should I use buffered streams?
    Thanks in advance !

    Gonen wrote:
    CeciNEstPasUnProgrammeur wrote:
    Heck, I often asked myself that, too. If only there were any documentation for those classes one could read...
    The buffer allows the stream to read a whole chunk of data, even though your program requests it one byte at a time. Reading larger chunks from a file e.g. is much faster than trying to read single bytes. Especially considering that usually, a whole cluster is read and you'd discard all but one byte, and then repeat the same...so if the buffered is faster . why there is un buffered streams?Lots of reasons. Maybe you're sure you're going to send or receive all the data in one transaction, so you don't want to waste memory on another buffer. Maybe you're sending data to a device that requires real-time input, like a robotic arm.

  • Download of .zip file causes 1)stream of 'untitled' tabs & 2)download win doesnt open - why?

    tried to download .zip files from Deitel.com and InformIT.com -- download worked in Internet Explorer, caused a stream of tabs L to R on the Firefox 3.6.8 browser screen, flickering download window, but no files were delivered -- waited 5 min. The tabs were labeled 'untitled'.
    Host system Windows 7 Home User.

    Firefox sometimes has this tab proliferation when there is a mixed signal about which program is supposed to handle the download, the browser or an external program. If you check here:
    Tools > Options > Applications
    then type zip in the search box and wait for it to filter...
    Make sure none of the items is supposed to be opened with Firefox.

  • The action file print causes PS CS5 to hang, stop responding

    The action file print causes PS CS5 to hang, stop responding
    Its installed on a Win 7 64 bit PC i7 with 6G ram
    PS is version 12.0.4 64 bit
    The print dialouge box does come up eventualy around 10 mins later (some times).   While waiting PS is totaly dead and the task manager shows it as not responding
    Anyone got any ideas?

    I might suggest seeking out an updated printer driver to see if that will help.
    Is it possible you have a network path configured in there somewhere that's pointing to something no longer available on your network?
    -Noel

  • Some emails from a particular sender causing Outlook 2010 to hang, task manager shows memory use spikes

    Posting this to the Exchange forum because I'm hoping there's a server-side solution.
    SOME emails received from an external sender (gmail.com address, not sure the mail client) are causing Outlook 2010 to hang when trying to open the email.  Outlook becomes non-responsive when viewing the email through the preview pane or by double-clicking
    the email.  If I open Task Manager I see that the outlook.exe process memory use starts increasing very quickly.  As far as I know the only resolution is to end the task and re-open Outlook (and avoid that email).
    I've found several excellent threads on these same symptoms, but there seems to be a variety of causes.  I've tried a bunch of things so far:
     - Tried opening from another system on our network running Outlook 2010, same issue. 
     - Tried opening from OWA, opens fine.
     - Tried exporting the email to a PST, then opening from a completely different system outside of our network, but still running Outlook 2010, same issue.
     - Tried exporting the email to a PST then opening from a completely different system outside of our network, running Outlook 2013, email opens fine.
     - Tried setting Outlook to open all emails as PLAIN TEXT, opens fine.
    Systems are running the latest Outlook 2010 SP and patches, and running a variety of OS's.  Only common denominator seems to be Outlook 2010.
    I was hoping to find a way to convert incoming emails from this sender to open as Plain Text using a Hub Transport rule, but cannot find a way to do it.
    Unfortunately I have no control over the sender, so don't know what could be triggering the problem.  
    Can anyone advise on a possible solution?  Any way to someone convert emails from a particular sender to Plain Text automatically?

    Either you inform the sender to configure in sender's outlook to send only to you in plain text please check this
    http://office.microsoft.com/en-001/outlook-help/change-the-message-format-to-html-rich-text-or-plain-text-HA101992313.aspx
    Or
    Call a macro in your outlook example below. Please check
    this for details
    Dim msg As MailItem
    For Each msg In myNS.GetDefaultFolder(olFolderInbox).Items
       If msg.Unread = True And _
         msg.SenderName = "Linda Cooper" Then
    Item.BodyFormat = olFormatPlain
       Else
         ' Message doesn't meet criteria.
       End If
    Thanks,
    MAS
    Please mark as helpful if you find my comment helpful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you.

  • Enabling Drill Through causing Essbase Integration Server hang.

    During the automation process using olapicmd command and *.cbs we are enabling Drill Through which is causing Essbase Integration Server hang.
    We don't get any error message in log file. Plus sometime its run successful , also when we run this manually going to EIS console, it run fine.
    Thanks in advance
    -Piyush

    Hi Kishore,
    Thanks for your prompt reply......
    I have checked in before itself the Drill down option ......
    I am not able to understand whats the issue we are able to drill through in EIS till last level but after improting in OBIEE we are not able to drill through to last level, in the last level it showing no results....
    I am not able to find the solution any other suggestions ?
    Regards,
    Tarang Jain

  • What is - Re buffering stream, and WHY.......

    When I listen to a song 30 second preview, I often get this message show several times: *Re buffering stream*.
    It's _very annoying_ because each time the balloon pops up with that message, the song +stops playing+...
    ... then it +starts up again+, until it happens again..
    *Fed up!*

    Assuming a large table, number two would be the fastest. If empno in unique, you can leave out the where exists part and just select x from emp where empno = 20. If empno is not unique, then using where exists can be faster. Assuming that empno is not unique, query 1 may elect to scan the whole table looking for that empno. Number 2 can use the index and return your result in, typically, three LIOs.
    Again, it all depends on your indexing, size of tables, and uniqueness of key upon which you are searching.

  • Compensation of delay caused by activity

    Hi Experts
    During the execution phase, it is observed certain activities have taken more duration than the planned.
    At this juncture, to cover up the deviation, is there any facility to understand where this lagging can be compensated.
    Or, can i use the reduction functionality, to compensate the delay caused by the already executed activities?
    warm regards
    ramSiva

    the quesion is, do you want to compensate the time technically or for your real business case.
    Technically you can simply shorten the duration or maintain the remaining duration or forecast fnishdate to compensate the delay. Surely you can using reduction functionality.
    In the real life, either the you need more capacity (e.g. instead a person using multipe persons) or the person has to to the night shift.
    Kind regards,
    Zhenbo

  • Delay caused by encryption

    Hi Expert,
    Could anyone enlighted me on the delay time to be occurred after the encryption (AES 128) is enabled? Below please find the existing information for your reference.
    Site A:
    Router: 7200VXR
    WAN circuit: 5M
    Case 1: 256K traffic will be sent from site A to site B and last for 5 minutes.
    Case 2: 256K traffic will be sent from site A to site B and last for 5 minutes with AES 128 to be in placed.
    Site B:
    Router: 7200VXR
    WAN circuit: 3M
    Case 3: 256K traffic will be sent from site B to site A and last for 5 minutes.
    Case 4: 256K traffic will be sent from site B to site A and last for 5 minutes with AES 128 to be in placed.
    Any reference URL regarding delay caused by encryption would be much appreciated.
    Anita

    @Joe D.
    I'm using LabVIEW 2010. The actual VI is part of a large, complex system that there would be no way for me to upload here. I've made a simple, bare-bones VI, though, that simulates what we need to do and reproduces the problem.  The attached VI requires an img1.jpg and an img2.jpg in the same folder as the VI. Note that we could have much more than 2 images, so although in the example VI re-drawing the images in the hidden picture box isn't necessary, it is needed in our actual system.
    @Yamaeda
    Thanks again for your suggestions. I looked into pict rings, but I couldn't figure out a way to programmatically populate them. It seemed like all the images had to be loaded ahead of time. I tried the .NET PictureBox without success but I'll give it another shot. It just seems unreasonable to me that displaying an image would take that long. It isn't a restriction due to the Computer or OS itself, because I know this can be done in C++ and I think even in MATLAB. It also seems like no matter what I use to draw or show the image, and whether it's in parallel or not, the delay occurs as if's delaying all of LabVIEW's threads no matter what.
    Attachments:
    imgDisplay_demo.vi ‏52 KB

  • Adding a Delay To A Stream.

    Yes, I want to do the exact opposite of most of you. I want to add a 10-15 minute delay into a stream for PvP.
    I did not see a thread on this so I thought I'd ask what would be the best way to do this? The answer perferably doesn't require another computer, but if that's the only route... I can go that way...

    Another way requires you to write a DirectShow filter that takes data from the device and keep it in it's queue for some duration (the amount of latency you want in stream). If this could be implemented, you can achieve what you want with utmost precision but this approach requires knowledge about writing DirectShow filters.

  • Buffering / streaming video

    How can i retrieve information about buffering / streaming
    state of flash
    video when flash video is buffering / streaming?
    I'm displaying a flv from flash and i'm not using controller
    component
    (which displays "streaming..." in its scroll bar when video
    is streaming)
    because of lack of space on screen, so i'm trying to find
    another way to
    display information to a user about buffering / streaming
    state of currently
    displayed video (external flv).
    I'm using Flash 8 proffesional
    Thanks
    Luka

    Ok, thanks. Ill do my best to understand it myself from the
    help about
    NetSteam Class
    Thanks Again
    "Rothrock" <[email protected]> wrote in
    message
    news:e4q0o7$lvn$[email protected]..
    > So you are using the NetStream class? If that is the
    case then read the
    help
    > files for the NetStream class. There is
    NetStream.bufferTime,
    > NetStream.bufferLength, NetStream.setBufferTime(), and
    NetStream.onStatus.
    >
    > I think those should pretty much do what you need. They
    will have to,
    since
    > that is pretty much what there is.
    >

  • Firefox regularly hangs after an unspecified period of use, and causes other programs to hang, and a forced system shutdown is necessary.

    The firefox browser hangs after an unspecified period of time. Anything from a few minutes after system startup, up to 5-6 hours of use or perhaps more. Attempting to use other programs including windows explorer while firefox is hanging causes those programs to hang also, making a forced shutdown necessary. Occaisionally I've noticed firefox will respond, perhaps after 10 or more minutes. There seems to be no hard disk activity while the program hangs. Memory usage of firefox on my system is usually upwards of 190,000.

    I have circumvented this mostly by running internet explorer, and using Firefox only for browsing when I need to make use of it's addons. In this way I've had the problem re-occur maybe once or twice in the past two weeks. It's not really a solution but it does seem to help, and I'm no longer sure the problem IS firefox but using it certainly exacerbates the problem.
    I've only just updated to firefox 6, so I am not entirely sure how that will go just yet.

  • Buffering/streaming hesitation on video playback

    Please help,
    I have tried following and combos thereof to improve video playback;
    (Buffering & Streaming)
    1) System properties; Advanced Tab; Settings in Performance; Advanced Tab;
    (Virtual Memory, increase Paging File Size by 100 and 150.)
    2) Display; Properties; Settings; Advanced Tab; Troubleshoot;
    (Hardware Acceleration from Full to None.)
    3) Media Player; Tools; Options; Performance;
    (Change connection speed)
    ( Network Buffering)
    (Video Acceleration, Full to None)
    4) FireFox; Tools; Options; Content;
    (All combos of Block Pop-ups; Load Images; Enable Java and Advanced Tab)
    5) All plug-ins are updated
    Used to function properly, but something now interferes…
    Fire Fox ?
    Add-Ons ?
    Plug-Ins ?
    What may have happened?
    Retired @ 76… [email protected]

    In Firefox '''Help''' ('''Alt''' + '''H''') > '''Troubleshooting Information''' > '''Open Containing Folder''', would open the current profile folder. You can copy the individual files or the whole folder to another safe location. This would ensure that personal data files like the bookmarks, website passwords etc. are safely backed up. Please also see [https://support.mozilla.org/en-US/kb/Backing%20up%20your%20information?s=backup&r=1&e=sph&as=s this].
    After creating a new profile and starting Firefox in that new profile, you can '''Open Containing Folder''', exit Firefox and copy and overwrite the history + bookmarks file ('''places.sqlite'''), passwords ('''key3.db''' + '''signons.sqlite''') etc. from the backup to this folder.
    You can also try to check the current internet connection speed and ensure that OS network settings are okay: http://pingtest.net/

Maybe you are looking for

  • ITunes quits when I refresh podcasts with iPod touch connected

    If I click the "refresh podcast" button in iTunes (version 11.3.1.2) while my iPod touch (32G capacity currently with 4.5G available; still running iOS 5.1.1) is connected, iTunes quits. If the iPod is not connected, the refresh runs just fine; any a

  • 0 Swap File virtual memory

    My computer has been a dog for awhile now. I finally got Activity Monitor to open (long story). And I noticed that I have  6 GB swap file, but none of it is being used despite all of my ram being allocated. I am certain that this creates slow downs..

  • If i want to schedule back ground job on dtp how to do

    if i want to schedule back ground job on dtp how to do

  • Ipod as a gift... Can I preload the music?

    I want to buy my grandmother an IPOD as a gift. As you can imagine, technology is not really her thing. Eventually, she will learn to load new music, but I would like to preload music on it and give it as a present. If I load music on it, will there

  • Verizon Iphone 4s, Youtube/Facetime not working

    Just got my phone, these features havn't worked sense I got it. Ive tried using several diffent wifi locations to make sure it wasnt my own but, eveytime I try to launch a youtube video it says "Cannont connect to YouTube" and face time says "Could n