[ https://issues.apache.org/jira/browse/GEODE-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15323081#comment-15323081 ]
Kevin Duling commented on GEODE-68: ----------------------------------- Requesting comments [~amb] [~bschuchardt] Testing by forcing a DNS timeout, I've found that the response could take as long as 75 seconds. Clearly, that's too long. So there are a couple of alternatives. * Start a background thread when gfish first starts up to collect and cache the hostname so that if there is a DNS timeout, avoid exposing it to the user. * Adopt the suggestion posted on many, many stacktrace.com threads. This is the controversial {{System.exec("hostname")}} command. There are several good reasons to do this. * hostname exists on Windows (c:\Windows\System32\hostname.exe) as well as Linux, *nix, Solaris, and Mac (/usr/bin/hostname) * Takes approximately 20ms to process. * Will return the POSIX name of the system as [~markito] requested, not the name of a NIC. * It can be the fallback if the appropriate environment variable is not set. Below is a test program I've done to validate the behavior and get some timings. I've also tested this by calling "hostnme" instead of "hostname" and verified the behavior if the command doesn't exist, defaulting to 'unknown'. {code} import java.io.IOException; import java.io.InputStream; import java.util.Scanner; public class Host { public static void main(String[] args) throws IOException { long mark = System.currentTimeMillis(); String hostname; hostname = System.getenv("COMPUTERNAME"); // Windows if (hostname == null) { hostname = System.getenv("HOSTNAME"); // Unix / Mac / Cygwin sometimes has this set } if (hostname == null) { try { hostname = execReadToString("hostname"); // Unix / Mac / Windows / Cygwin } catch (IOException io) // happens if hostname binary is not found. { hostname = "unknown"; } } if (hostname == null) // if it still isn't set, default it. { hostname = "unknown"; } System.out.println(hostname + " " + (System.currentTimeMillis() - mark) + "ms"); } private static String execReadToString(String execCommand) throws IOException { Process proc = Runtime.getRuntime().exec(execCommand); try (InputStream stream = proc.getInputStream()) { try (Scanner s = new Scanner(stream).useDelimiter("\\A")) { return s.hasNext() ? s.next() : ""; } } } } {code} > GFSH SYS_HOST_NAME variable should report hostname if available > --------------------------------------------------------------- > > Key: GEODE-68 > URL: https://issues.apache.org/jira/browse/GEODE-68 > Project: Geode > Issue Type: Bug > Components: gfsh > Reporter: William Markito Oliveira > Assignee: Kevin Duling > Priority: Minor > Labels: gfsh > > SYS_HOST_NAME is actually displaying SYS_USER_HOME. > This is very useful for automation scripts. > {code} > gfsh>echo --string=$* > Property | Value > ------------------------------ | > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > APP_COLLECTION_LIMIT | 20 > APP_FETCH_SIZE | 1000 > APP_LAST_EXIT_STATUS | 0 > APP_LOGGING_ENABLED | false > APP_LOG_FILE | /Users/wmarkito/gfsh-%u_%g.log > APP_NAME | gfsh > APP_PWD | /Users/wmarkito > APP_QUERY_RESULTS_DISPLAY_MODE | table > APP_QUIET_EXECUTION | false > APP_RESULT_VIEWER | basic > SYS_CLASSPATH | > /Users/wmarkito/Pivotal/GemFire/sources/github/gemfire/build-artifacts/mac/product/lib/gfsh-dependencies.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/tools.jar > SYS_GEMFIRE_DIR | /Users/wmarkito/... > SYS_HOST_NAME | wmarkito > SYS_JAVA_VERSION | 1.7.0_72 > SYS_OS | Mac OS X > SYS_OS_LINE_SEPARATOR | > SYS_USER | wmarkito > SYS_USER_HOME | /Users/wmarkito > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)