Uploaded image for project: 'Hadoop HDFS'
  1. Hadoop HDFS
  2. HDFS-10412

Add optional non-thread support for better perfromance

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • libhdfs
    • None

    Description

      I would like to propose some simple optional changes that would be activated by a compiler flag. These changes would enable a typical monolithic single threaded application to use libhdfs without the need to incur additional overhead for threads that is not needed.

      Here is a proposed for these changes:

      #1 add a new function to "jni_helper.c"

      /** getSoloJNIEnv: A helper function to get the JNIEnv* for non-threaded use.

      • If no JVM exists, then one will be created. JVM command line arguments
      • are obtained from the LIBHDFS_OPTS environment variable.
      • @param: None.
      • @return The JNIEnv* for non-thread use.
      • */
        JNIEnv* getSoloJNIEnv(void)
        {
        JNIEnv *env;
        env = getGlobalJNIEnv();
        if (!env) { fprintf(stderr, "getJNIEnv: getGlobalJNIEnv failed\n"); return NULL; }

        return env;
        }

      Add the following the following to "hdfs.c"

      #1 a static global variable : "JNIEnv* hdfsJNIEnv;"
      #2 a MACRO: "GETJNIENV();"

      #ifdef NOTHREAD
      static JNIEnv* hdfsJNIEnv = NULL;
      #define GETJNIENV() \
      if (hdfsJNIEnv == NULL)

      { \ hdfsJNIEnv = getSoloJNIEnv(); \ }

      \
      env = hdfsJNIEnv;
      #else
      #define GETJNIENV() env = getJNIEnv();
      #endif

      The above NEW MACRO would be used as in the following example:

      int hdfsFileGetReadStatistics(hdfsFile file,
      struct hdfsReadStatistics **stats)

      { jthrowable jthr; jobject readStats = NULL; jvalue jVal; struct hdfsReadStatistics *s = NULL; int ret; JNIEnv* env; // JNIEnv* env = getJNIEnv(); GETJNIENV(); ( ... ) }

      Attachments

        Activity

          People

            Unassigned Unassigned
            stevebovy Stephen Bovy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 168h
                168h
                Remaining:
                Remaining Estimate - 168h
                168h
                Logged:
                Time Spent - Not Specified
                Not Specified