/** * Await for the transmit to be complete * * @param timeout * wait timeout * @param unit * wait timeout unit */ int awaitTransmitComplete(long timeout, TimeUnit unit) throws Exception { return Await.result(transmitComplete, Duration.fromTimeUnit(timeout, unit)); }
logger.info("Waiting for closing all streams ..."); try { Await.result(closeResult, Duration.fromTimeUnit(5, TimeUnit.MINUTES)); logger.info("Closed all streams in {} millis.", closeStreamsStopwatch.elapsed(TimeUnit.MILLISECONDS));
@Override protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final int profileDurationSecs = HttpServletRequestParams.getInt(req, "seconds", 10); final int profilePollRate = HttpServletRequestParams.getInt(req, "hz", 100); LOG.info("Collecting CPU profile for " + profileDurationSecs + " seconds at " + profilePollRate + " Hz"); Duration sampleDuration = Duration.fromTimeUnit(profileDurationSecs, TimeUnit.SECONDS); CpuProfile profile = CpuProfile.recordInThread(sampleDuration, profilePollRate, stateToProfile).get(); resp.setHeader("Content-Type", "pprof/raw"); resp.setStatus(HttpServletResponse.SC_OK); OutputStream responseBody = resp.getOutputStream(); try { profile.writeGoogleProfile(responseBody); } finally { Closeables.close(responseBody, /* swallowIOException */ true); } } }
logger.info("Waiting for closing all streams ..."); try { Await.result(closeResult, Duration.fromTimeUnit(5, TimeUnit.MINUTES)); logger.info("Closed all streams in {} millis.", closeStreamsStopwatch.elapsed(TimeUnit.MILLISECONDS));
Backoff.exponential( Duration.fromTimeUnit(100, TimeUnit.MILLISECONDS),
public static void main(String[] args) { try { String serverHostName = InetAddress.getLocalHost().getHostName(); PinLaterQueueConfig queueConfig = new PinLaterQueueConfig(CONFIGURATION); queueConfig.initialize(); String backend = CONFIGURATION.getString("PINLATER_BACKEND"); PinLaterBackendIface backendIFace = getBackendIface(backend, serverHostName); PinLaterServiceImpl serviceImpl = new PinLaterServiceImpl(backendIFace, queueConfig); PinLater.Service service = new PinLater.Service(serviceImpl, new TBinaryProtocol.Factory()); ServiceShutdownHook.register(ServerBuilder.safeBuild( service, ServerBuilder.get() .name("PinLaterService") .codec(ThriftServerFramedCodec.get()) .hostConnectionMaxIdleTime(Duration.fromTimeUnit( CONFIGURATION.getInt("SERVER_CONN_MAX_IDLE_TIME_MINUTES"), TimeUnit.MINUTES)) .maxConcurrentRequests(CONFIGURATION.getInt("MAX_CONCURRENT_REQUESTS")) .reportTo(new OstrichStatsReceiver(Stats.get(""))) .bindTo(new InetSocketAddress(CONFIGURATION.getInt("THRIFT_PORT"))))); new OstrichAdminService(CONFIGURATION.getInt("OSTRICH_PORT")).start(); LOG.info("\n#######################################" + "\n# Ready To Serve Requests. #" + "\n#######################################"); } catch (Exception e) { LOG.error("Failed to start the pinlater server", e); System.exit(1); } } }