Upload file writes too fast in while loop

problem scenerio:
My upload thread occasionally rushes through its while-write loop, writing data for a 3mb image in less than a second and then it waits for a longer time (10-30 seconds) for a response. The thread is writing directly to the OutputStream class using OReilly's implementation. I do not understand this delay. It appears to be buffering? I would like real time progress, which will be reflected in a progress bar. Is there something peculiar about this please:
The corresponding console output is (for each image where the 1657 and 1907 times indicates problematic behavior):
bufferSize: 8192, whileloopWriteTime: 40125, waitForResponseTime: 500
bufferSize: 8192, whileloopWriteTime: 31937, waitForResponseTime: 625
bufferSize: 8192, whileloopWriteTime: 1657, waitForResponseTime: 27843
bufferSize: 8192, whileloopWriteTime: 1907, waitForResponseTime: 33734
bufferSize: 8192, whileloopWriteTime: 48719, waitForResponseTime: 641
bufferSize: 8192, whileloopWriteTime: 34578, waitForResponseTime: 688
upload code (in an applet):
               private int bufferSize = 8192;
               private byte[] buffer = new byte[bufferSize];
               private Socket socket;
               private OutputStream os;
               ..... etc
               os = socket.getOutputStream();
               ..... etc
               // write the file bytes to the socket
               int bytesReadIn=-1;
               while ( ((bytesReadIn = fis.read(buffer)) != -1) )
                    write(buffer, 0, bytesReadIn);
               write(strLFBoundaryLF);
               if(socket != null) socket.shutdownOutput();
               // read response section
               String strResponse="";
               String strInputLine="";
               br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
               while( (strInputLine = br.readLine()) != null ){
                    strResponse=strInputLine.trim();
                    if(strResponse.indexOf("RES:") != -1) break; // contains bytes
                    if(socket==null || !socket.isConnected()){ intError=ERROR_SOCKET; break;}
               if(socket != null) socket.shutdownInput();
....etc
     private void write (byte[] buf,int offset,int size) throws Exception {
               os.write (buf,offset,size);
============================================================================
jsp page receives the call from the applet:
          else if (part.isFile()) {
               FilePart filePart = (FilePart)part;
               String fileName = filePart.getFileName();
               String filePath = filePart.getFilePath();
               String strServerFilePath = fileInfoStorage.getServerFilePath(filePath);
               File SaveFile = new File (strServerFilePath);
               (SaveFile.getParentFile()).mkdirs();
               if(fileName != null) {
                    FileOutputStream outStream = null;
                    try {
                    outStream = new FileOutputStream(SaveFile);
                    lgBytesTransferred += filePart.writeTo(outStream); // writes directly to the file
                    outStream.flush();
... etc
=========================================================================
package com.oreilly.servlet.multipart;
FilePart class
... etc
long write(OutputStream out)
throws IOException
if(contentType.equals("application/x-macbinary"))
out = new MacBinaryDecoderOutputStream(out);
size = 0L;
byte buf[] = new byte[8192];
int read;
while((read = partInput.read(buf)) != -1)
out.write(buf, 0, read);
size += read;
return size;
public long writeTo(OutputStream out)
throws IOException
long size = 0L;
if(fileName != null)
size = write(out);
return size;
}

Thank you for your responses.
Accurately reporting the upload progress to the user is required, however a timely upload is also imporrtant.
At present data appears to be sitting in a buffer for 10-20 seconds, while the progress bar indicates complete and before the next file upload is
started.
I am not using swing. I use an (non-gui) applet which handles communication between the server (jsp, servlet) and a dhtml, css interface.
In the gui I a list of items awaiting upload is created. The gui paints a progress bar next to an item which is in progress (uploading).
When an individual item's progress bar reaches 100% (confirmed to disk) the text 'complete' replaces the progress bar.and a the next item receives a progress bar. The gui also paints updates to a second global progress bar which indicates overall progress. The uploads are reliable, but for this issue.
There's not much information except timing information in your post, and what would help us make educated guesses into what your program does are "etc."ed. Notably, does your applet maintain a single connection to your server for all image uploads?
Presently the applet creates a new socket for each request. Another class manages and monitors the socket connection. The socket connection
runs in its own thread. At the end of each file upload the socket and thread terminate. Once the upload behavior is stable I will attempt a more
elaborate thread and socket management scheme.
>
Try acquiring more information with a network analyser such as Wireshark.
I have wireshark. I will try and post results. However I placed a System.out.println in the
O'Reilly class which receives the data and it appears to receive and write the file data (via OutputStream.write) in 1-2 seconds as
reflected in the applet output.
>
This bizarre suggestion at least contains the germ of the issue. Your writes are just writing to the socket send buffer, not to the network. I would
increase the socket send buffer size personally.
I have not tested an increased socket send buffer size. This feels right. I will test this tomorrow and report back. Do you have a suggested socket send buffer size?
Your suggestion that I am writing to the socket and not the network would certainly reflect the results I am witnessing.
In the O'Reilly class data is being written from the incoming stream (8192 bytes per loop) to the file using the OutputStream write method. However because the data is writes are so fast it appears to be writing to a buffer and not the file.
Yeah. Next question is is this really the O'Reilly code? that keeps testing the socket for null and isConnected() after it's already been in use and can't possibly be in any other state?
This code which is testing the socket is not the O'Reilly code. The O'Reilly code is the FilePart class.

Similar Messages

  • Can't write to instrument in while loop.

    in  my case, I use 2 while loop for the progarm. one is to write the data to the instrument, another one is use local variable to change the data depend on time. the problem is the data which need write to the instrument does change. but another while loop doesn't write it to the instrument unless I push highlight excution in the diagram or choose save as in the file. could anybody help me to find the problem?

    Hi Akuma,
    the fact that it works when you highlight execution implies (perhaps) a race condition. The lightbulb serializes the execution of your VI, so that functions execute in succession although they don't depend on each other. When you then run the VI in realtime, some functions are executed at the same time, e.g. "VISA flush buffer" and "VISA write". It is important to define the order the VIs execute on your VISA interface for instance by wiring the error-cluster.
    If this doesn't help, then post your VI (or a simplified version) or a screenshot of the diagram.
    Greets, Dave
    Greets, Dave

  • .mov files - video too fast, audio ok

    HI!
    I have a problem with .mov files. They play and the sound is ok, but video plays too fast and i ahead of audio. I'm sure the video is too fast, because i can see when someone is talking that it's way too fast. I've tried reinstalling quictime, installing older versions, reinstalling direct x and graphics drivers. I even tried quictime alternative. Nothing helps. This happens to files that i have on my disc.And it only happens on my computer, on my brothers it plays just fine, so the files are ok.
    Can anyone help?
    thnx, Blaz
      Windows XP Pro  
      Windows XP Pro  

    same here 39sec video is imported as 20 sec video... any help?

  • Video on imported AVCHD files is too fast

    I recently got a Panasonic Lumix that shoots AVCHD video. I upgraded to iMovie '09, since it is supposed to be AVCHD-compatible. However, the AVCHD files I imported in iMovie have the video playing super fast, while the audio is normal. I've tried switching between NTSC and PAL formats, with no change.
    Anyone else experience this? Anyone know why this is happening? Help please?

    First, work through all of the steps here http://ppro.wikia.com/wiki/Troubleshooting
    If your problem isn't fixed after you follow all of the steps, report back with the DETAILS asked for in the questions at the end of that link
    PS you are in the wrong forum http://forums.adobe.com/community/premiere/premierepro_current

  • Imported files play too fast

    I am recording lectures on an MP3 player/recorder. The lectures are usually 90 minutes long, my mo3 recorder stores the data as WAV files / 16Bit / 8.0hz.
    I want to open the files in Garageband so I can cut them into sections for later use.
    At the moment I am using a freeware application called Amadeous to convert the files to AIFF for importing into Garageband.
    WHen I play the track/s in Garageband however, they play like they are being fast forwarded.
    How can I get around this problem?
    Chris

    I've heard of this problem twice, I think. I've never been able to duplicate it, and I don't think we ever figured out the cause or solution.
    I guess the first thing I'd suggest trying is create a brand new GB file and drop the AIFF into that.
    The only other thoughts are the standard "try this" procedures:
    o Repair Permissions
    o Delete GB's prefs Files
    . (Search your Hard Drive for "GarageBand" and delete the files that end in ".plist" and ".cs")

  • CS4 premiere Imported .avi files play too fast

    Hi Guys
    I have a problem. I'm new to CS4 having used Adobe Premiere 6.0 in the past and I have never had this issue when importing .AVI files. What happens is that the file play fine in my windows enviroment and on all my players VLC,DIVX, Windows media player.
    But as soon as I import these files into my project at 29.97 frames the video plays really really fast and the sound plays at the normal rate. If I try to change the frame rate the sound also changes. Now here is the strange part. If I convert the files to MP4 they play fine! but the quailty of the video takes a massive hit as you know.
    I tried to convert the files to .MOV, MPG (which the program won't play) and most other types of video files but MP4 seems to be the only one that works! When I really want the higher quailty .AVI. Again the files play fine outside of CS4 Premiere and I have already converted them from a Panasonic AVCHD encode format.
    Please if anyone has any advise it would be great as I have to get this sorted for a x-mas present!
    Richard
    Running
    Windows Vista Ulimate
    4GB RAM
    Quad core Intel chip
    CS4 version 4.1.0

    First, work through all of the steps here http://ppro.wikia.com/wiki/Troubleshooting
    If your problem isn't fixed after you follow all of the steps, report back with the DETAILS asked for in the questions at the end of that link
    PS you are in the wrong forum http://forums.adobe.com/community/premiere/premierepro_current

  • While loop doing AO/AI ... Performanc​e?

    Hi!
    I have been trying to get a VI to do concurrent Analog
    data in and out and both the input and output rates and
    waveforms can change while the VI is running. My problem
    is this:
    (a) If I try putting the read and write operations in
    separate while loops, one or the other loop will
    die in a buffer over/underrun.
    (b) If I put both into the same loop, then this works
    but I am limited in the choice of data-rate parameters
    because eventually one or the other DAQ VI will take
    too long.
    At this point I have only one loop and the buffers are big
    enough to hold 10 iteration. Every time one of the loops
    dies I reset it. Still this seems awkward. Is there a
    way of improving on the loop overhead and putting t
    he
    input and output in separate loops? Or any other way to
    improve performance?
    Rudolf

    Ok, I knew that ocurences did something useful but I am
    still a bit confused:
    * Can you set an occurrence for an output event. None
    of the examples I've seen say so but it looks like
    it should work
    * How do occurrences actually help with the "hanging"
    problem. Does the compiler see the occurrence in
    a loop and change the wait parameters?
    I looked at devzone but most of the stuff I found there,
    even the promising looking stuff was all about
    synchronizing and triggering, not about occurrences.
    Rudolf
    JB wrote:
    : Once in the read function, the program "hangs" until the number of
    : data points is in the buffer. The same applies to the write function.
    : This means that most of the time, your program is waiting.
    : To sol
    ve this problem, you must use DAQ occurrences (--> hardware
    : events).
    : For examples for using daq occurrences, type "daq occurrence" in the
    : search of the LabVIEW help or even better, at
    : http://zone.ni.com/devzone/devzoneweb.nsf
    : Hope this helps

  • How to name a uploaded file in server

    Hi,
    I am trying to upload files in to my server. Then save it with a unique name and process it.
    The following codes can upload the file but I dont know how to save the file with a unique name and then pick up the unique name and process the file.
    I need this because
    1# Multiple people will upload files at the same time. Therefore I need some mechanism to mark individual file and process it.
    Any help will be very much appreciated. Most importantly please be little collaborative. I am just one week old JSP boy :-).
    try {
                List fileItemsList = servletFileUpload.parseRequest(request);
                DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
                diskFileItemFactory.setSizeThreshold(102400); /* the unit is bytes */
                File repositoryPath = new File("/temp");
                diskFileItemFactory.setRepository(repositoryPath);
                /* Iterating through the uploaded file*/
                Iterator it = fileItemsList.iterator();
                while (it.hasNext()){
                    FileItem fileItem = (FileItem) it.next();
                    /* Playing around with the uploaded file */
                    getName = fileItem.getName(); /*File name provided by the browser*/
                    fileSize = fileItem.getSize(); /*File size in Bytes*/
                    File saveTo = new File("/upload_files");
                    fileItem.write(saveTo);
                   

    merit wrote:
    Hi,
    Thanks. That should work but I was thinking of generating some thing random.
    I think what ever i enter into "someUniqueName" then file will always be named as "someUniqueName". What would happen if 2 or more people uploads different file at the same time?Use the name of the original file. If File#exists() returns true, then suffix it with a counter or so.
    You can find here an article about a file upload filter which contains under each a basic demonstration example with a servlet which does exactly that using FileUtil#uniqueFile(): [http://balusc.blogspot.com/2007/11/multipartfilter.html].

  • Starting new while loop while old one still running

    Hi!
    I am attempting to write video images to AVI files. I want to give the user the option to decide when they want to begin to capture the images. I place the "start recording" button in one loop and the image acquisition and AVI Write subVIs in another loop. LabVIEW won't allow me to continue on with the image acquisition loop until I finish with the "start recording" loop. Any ideas how to fix this (to allow the image acquisition to start and continue having LabVIEW check for a button press on "start recording")?
    Attachments:
    Capture_and_Save_as_AVI.vi ‏177 KB

    Thanks. I suspected as much. In any event, I can't seem to find a good configuration of while loops and case structures which will produce the desired results. I want to start acquiring images and allow the user to choose to start recording at any time he desires. This issue is further complicated by the fact that the status of the "Start recording" must be checked at all times, but only initialized once, while the AVI Write Frame depends on that first initialization step but must be looped continuously aferwards in order to 'keep up' with the images being acquired. In the newly attached example, I placed the case structure inside the image acquisition while loop and the avi write frame inside a while loop inside of that case structure. unfortunately,
    labview decides to stay inside the avi write frame while loop after entering, instead of returning to the image acquisition while loop. i can't place the avi write frame inside the general image acquisition while loop because then labview will think i want to initialize the avi write frame right away and will return an error when avi write frame isn't provided with an avi refnum. Ideas?
    Attachments:
    Capture_and_Save_as_AVI.vi ‏174 KB

  • The offset in the file is too big"? Other than, hey it's FAT formatted, etcetera!

    Does anyone have an answer for "The offset in the file is too big" error while creating a file using QT API "writeToFile"?
    I mean something other it's FAT formatted, not enough space, et cetera. Anyone?

    First how much free space do you have on your boot drive.  For normal use it's recommended to have a minimum of 10 GB free space.  If you use iDVD up that to 20-25 GB.  Lots of cache and swap space is needed.
    Create the slideshow in iPhoto, set the disiplay size ratio to 4:3 and export it out of iPhoto at the medium or large size. 
    Open a new project in iDVD and add the QT file to the iDVD menu being careful to avoid any dropzones.
    With a 90 minute slideshow you can use a single layer DVD disk. iDVD doesn't care about the file size of the media added to a project, only the playing time of the project, including menus.
    Follow this workflow to help ensure the best quality final product:
    Once you have the project as you want it save it as a disk image via the  File ➙ Save as Disk Image  menu option.  This will separate the encoding process from the burn process. 
    To check the encoding mount the disk image and launch DVD Player and play it.  If it plays OK with DVD Player the encoding was good.
    Then burn to disk with Disk Utility or Toast at the slowest speed available (2x-4x) to assure the best burn quality.  Always use top quality media:  Verbatim, Maxell or Taiyo Yuden DVD-R are the most recommended in these forums.
    You shouldn't try to create the slideshow in iDVD with still photos if the number of still photos is larger than 99.  That creates a pause or stall when playing back on many set top players. 
              OT

  • Offset in file is too big

    Does anyone have an answer for "The offset in the file is too big" error while creating a file using QT API "writeToFile"?
    I mean something other than "it's FAT formatted", "not enough space", et cetera. Anyone?

    Perhaps QT is not 64-bit and you are passing it something too big. Only people who know QT would know for sure.

  • While loop running too fast

    I have a while loop that is writing globals into shift registers. When the loop finishes i write these shift registers to a 2d Global array. Everything works great, my problem is that i am writing about 14000 readings/sec into the shift registers with a wait of 0 in wait until next multiple. File is way too big. If i change wait to 1, i get 500 readings/sec, too small. I need a way to slow this loop down, or put a delay in that is less than 1ms. Any help is Greatly Appreciated.
    Thanks
    Mike

    Pincpanter has some good ideas and is probably what you will need to do. 
    Keep in mind that tuning this way is very system dependant.  Changes in processor, processor speed, memory access speed, OS processes running, etc. will all affect the amount of time that LabVIEW takes and therfore takes a lot of tuning for each system.
    I just wish I had an even better answer, but I don't.
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • Multiple While Loops Write to One File

    Hello,
    I have three different instruments from which I am sampling, each at a
    different sampling rate.  Each instrument is being sampled in its
    own While loop.  How do I write all the samples I collect to a
    single text file?  I would like something in the following format:
    [Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
    [Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
    ...and so on..
    Thank you,
    Olyvia

    ofro wrote:
    I have three different instruments from which I am sampling, each at a different sampling rate.  Each instrument is being sampled in its own While loop.  How do I write all the samples I collect to a single text file?  I would like something in the following format:
    [Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
    [Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
    ...and so on..
    This seems like a flawed project.
    If each loop samples at a different rate, the samples will arrive at different times. Typically there won't be a single timestamp for all three samples. Can you explain what you actually want to write to the file from each loop?
    Do you want to write to the file incrementally inside each loop, or do you want to write everything at once after all loops have finished?
    LabVIEW Champion . Do more with less code and in less time .

  • Another novice question...I opened a file used "Concatenate String" to write to file creating headers and so forth...a "While Loop" routine is m

    onitoring a voltage and storing it to the same file under the associated header...What I'm having problems doing is after the loop is completed I need to write the MIN\MAX values of the voltage that was monitored in the "While Loop" once it completes. I juBefore the loop the "Concatenate String" peforms the following... line1 col.1 in an excel file is (Tester then Line1 col.2 (the testers name appears) next is a end of line. Then Line2 col.1 is (DATE)header then col.2(TIME)header then col.3(throttle voltage output)header then col.4(MAX VOUT)header then col.5(MIN VOUT) as i said this is perform before the loop with no pr
    oblem. Next during the "While Loop" the actual information for the DATE,TIME,Throttle voltage output,are inserted into Line 3 under the associated header with no problem. What I need to do is wait until the "While Loop" has completed to then store the MAX/MIN, but I can't seem to get the information to end up under the associated header. What do I need to set/use to accomplish this task? Thanks I've attached an excel spread sheet to give an example of where I need the values to be stored.
    Attachments:
    test1.txt ‏1 KB

    onitoring a voltage and storing it to the same file under the associated header...What I'm having problems doing is after the loop is completed I need to write the MIN\MAX values of the voltage that was monitored in the "While Loop" once it completes. I juThis can become hard depending on how much data you will be writing. If you could wait and write the data all at one at the end of the while loop it becomes easier. The problem is that when you write a file it writes it in rows of data not columns. I will attach an example (LabVIEW 6.0) that demonstrates how to do this. It is a hard to describe in text. Basically I create the new columns of data and write empty strings to them on each iteration of the while loop except for the first iteration. The first iteration I write a Max? and Min? into the column information. After the while loop is completed I search the array for Max? and Min? and replace it with the appropriate min and max values.
    Attachments:
    append_column.vi ‏47 KB

  • Why writes LabVIEW only every 2 seconds the measured Value to a Excel (In a while loop with 100 ms tact)?

    Hi everybody,
    I use the myDAQ to measure speed, ampere, and voltage of a battery driven motor. (For Current measurement, i use a Sensor which outputs a 0-10 V signal). I placed all DAQ-Assitants in a while loop with a [Wait until next ms multiple] clock and set a value of 100 ms. I thougt, Labview will now write into my text file 10 times a second all values. In fact, as you can see in the attached text file, Labview only writes in a unsteady interval of 1-2 seconds a value, which is too less.
    The question: Did I do anything wrong, how can you create VI that writes you lets say 10 values a second into text file? Or is simply the DigitalMultimeter input of the myDAQ not able to sample a rate of 10 Hz? I couldn´t find any information in the specification handbook about the sample rate of the DMM?
    If anyone can help me would be great! Thanx a lot, Markus
    Attachments:
    Measure Speed+Current+Voltage into Excel.vi ‏175 KB
    Test7.txt ‏1 KB

    File I/O is not very efficient. I recommend that you do you file logging in a parallel task. Have one task do your data acquision. This task would then pass the data to be logged to the logging task via a queue. That way your file operations do not impact your data acquision. Also, express VIs are not very efficient. You would be better off accessing that directly using the DAQ VIs. The express VIs contain lots of steps that do not need to be done every time you call it such as initializing the device.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Maybe you are looking for

  • Declaring variables in loops.

    I am wondering about how the compiler deals with variables that are declared within the loop they appear in. Obviously if you have a: while (loop == true);  { int var; // do something that involeves var...The suggestion is that it allocates an int wi

  • Checkout - modify record fails

    Hi all, I am facing a strange problem with Java API SP06. I am checking out the main table records and I am setting field values for a record. When i execute modifyrecords command for the checkedout maintable record, I am getting a server exception..

  • JSF 1.2 app is deployed only in exploded archive mode if JSF 2.0 facet used

    Hi. I'm developing JSF 1.2 + facelets application. The only way to configure eclipse WTP editors to properly handle xhtml pages is to install JSF 2.0 facet (there was facelets plugin before, but it was superseded by JSF 2.0 facet if I'm not mistaken)

  • WLAN Connection

    Hello, my wireless connection works, but at irregular intervals my MacBook Pro loses the connection to the WLAN. Sometimes I have to enter the WLAN identifier again. According to the Apple network analysis, everything works perfectly. Does anyone hav

  • Ipod classic won't connect with PC unless reset

    Everytime I conect my Ipod to my windows 7 pc it does not appear in the iTunes list as connected devices, the iPod screen also does not recognise the PC when connected via USB.  Reset the Ipod and it wil then connect as normal.   A reset needs to be