3 Replies Latest reply on Jan 31, 2012 9:39 PM by iron9light

    [-22]Error:= Invalid argument when write with AsynchronousFile

    iron9light

      I try to use AsynchronousFile for my own project.

      I got [-22]Invalid argument error.

       

      Here's the log:

       

      Jan 31, 2012 11:27:01 PM org.hornetq.core.logging.impl.JULLogDelegate error

      SEVERE: Libaio event generated errors, callback object was informed about it

      Jan 31, 2012 11:27:01 PM org.hornetq.core.logging.impl.JULLogDelegate warn

      WARNING: CallbackError: Error:= Invalid argument

       

      Here's the code[scala]:

       


      if (canWrite && !f.exists) f.createNewFile()

      val asyncFile = new AsynchronousFileImpl(null, executor)

      asyncFile.open(f.getAbsolutePath, 16) // FIXME: magic number

      asyncFile

       

       

       


      f: (Option[Throwable] => Unit) =>

          file.write(position, src.remaining, src, new AIOCallback {

              def done() {

                  f(None)

              }

              def onError(errorCode: Int, errorMessage: String) {

                  f(Some(new IOException("write error[%d]%s".format(errorCode, errorMessage))))

              }

          })

       

      Env: linux mint 11 64bit Oracle JDK 1.7.0_02 hornetq-2.2.5.Final

        • 1. Re: [-22]Error:= Invalid argument when write with AsynchronousFile
          clebert.suconic

          What kind of buffer are you using?

           

          Linux AIO requires Native Buffers, aligned to 512.

           

          So, the writes you make have to be aligned to 512.

           

          All the buffers on Java are already using the malloc version that aligns to 512. However releasing a native buffer in Java sucks, as the major portion will be outside of the JRE space, so GC will take longer usually than needed to release the native buffer. Because that I either reuse the buffers as most as I can or I use the native methods to allocate and release native buffers. (i.e doing my own control).

           

           

          Also: another thing I discovered is that libaio will have thread context control. If you make all the writes using a single thread you will get a higher throughput. (Believe it or not!). (Even if you use a SingleThreadExecutor to make all your writes).

          • 2. Re: [-22]Error:= Invalid argument when write with AsynchronousFile
            iron9light

            Now I use AsynchronousFileImpl.newBuffer(5120) to create my buffer

            But the size to write is src.remaining which is less than 512.

             

            Got the same -22 error.

             

            Dose the size need to be x512 too? If so, how about I only wanna write 32b and close the file?

             

            What does AsynchronousFileImpl.clearBuffer do?

             

             

            Best regards,

             

            IL

            • 3. Re: [-22]Error:= Invalid argument when write with AsynchronousFile
              iron9light

              size = x512 works.

              But how about I only wanna write less than 512b?