dropwizard jetty服务器请求超时

时间:2015-07-24 21:18:23

标签: jetty dropwizard

我有一个建立在dropwizard之上的web服务。有一个请求应该花费很长时间,请求客户端应该等待服务器响应。但我观察到的是,即使在应用程序可以处理之前,服务器也会响应请求。这是curl的输出

curl -vvv  --max-time 600 -H "Content-Type: application/json" -X POST -d '{"sourceId":0,"pastNMinutes":1440,"metricIds":[33570, 33571, 33572, 33573, 33574, 33575]}' http://localhost:30000/blitz-reader/metric-reader/reportedNodes
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 30000 (#0)
> POST /blitz-reader/metric-reader/reportedNodes HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:30000
> Accept: */*
> Content-Type: application/json
> Content-Length: 89
> 
* upload completely sent off: 89 out of 89 bytes
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

以下是配置yml

的http部分
# HTTP-specific options.
http:

  # The port on which the HTTP server listens for service requests.
  port: ${blitzReaderPort}

  # The port on which the HTTP server listens for administrative requests.
  adminPort: ${blitzReaderAdminPort}

  # Maximum number of threads.
  maxThreads: 300

  # Minimum number of thread to keep alive.
  minThreads: 10

  # The type of connector to use. Other valid values are "nonblocking" or "legacy". In general, the
  # blocking connector should be used for low-latency services with short request durations. The
  # nonblocking connector should be used for services with long request durations or which
  # specifically take advantage of Jetty's continuation support.
  # If you need SSL support, you can either choose from "nonblocking+ssl" or "legacy+ssl".
  connectorType: blocking

  # The maximum amount of time a connection is allowed to be idle before being closed.
  maxIdleTime: 60s

  # The number of threads dedicated to accepting connections. If omitted, this defaults to the
  # number of logical CPUs on the current machine.
  #acceptorThreads: 3

  # The offset of the acceptor threads' priorities. Can be [-5...5], with -5 dropping the acceptor
  # threads to the lowest possible priority and with 5 raising them to the highest priority.
  acceptorThreadPriorityOffset: 0

  # The number of unaccepted requests to keep in the accept queue before refusing connections. If
  # set to -1 or omitted, the system default is used.
  acceptQueueSize: 100

  # The maximum number of buffers to keep in memory.
  maxBufferCount: 1024

  # The initial buffer size for reading requests.
  requestBufferSize: 32KB

  # The initial buffer size for reading request headers.
  requestHeaderBufferSize: 6KB

  # The initial buffer size for writing responses.
  responseBufferSize: 32KB

  # The initial buffer size for writing response headers.
  responseHeaderBufferSize: 6KB

  # Enables SO_REUSEADDR on the server socket.
  reuseAddress: true

  # Enables SO_LINGER on the server socket with the specified linger time.
  soLingerTime: 1s

  # The number of open connections at which the server transitions to a "low-resources" mode.
  lowResourcesConnectionThreshold: 25000

  # When in low-resources mode, the maximum amount of time a connection is allowed to be idle before
  # being closed. Overrides maxIdleTime.
  lowResourcesMaxIdleTime: 10s

  # If non-zero, the server will allow worker threads to finish processing requests after the server
  # socket has been closed for the given amount of time.
  shutdownGracePeriod: 2s

  # If true, the HTTP server will prefer X-Forwarded headers over their non-forwarded equivalents.
  useForwardedHeaders: true

  # If true, forces the HTTP connector to use off-heap, direct buffers.
  useDirectBuffers: true

  # The hostname of the interface to which the HTTP server socket wil be found. If omitted, the
  # socket will listen on all interfaces.
  # bindHost: app1.example.com

#  ssl:
#    keyStore: ./example.keystore
#    keyStorePassword: example
#
#    keyStoreType: JKS # (optional, JKS is default)

  # HTTP request log settings
  requestLog:
    # Settings for logging to stdout.
    console:
      # If true, write log statements to stdout.
      enabled: false

    # Settings for logging to a file.
    file:
      # If true, write log statements to a file.
      enabled: true

      # The file to which statements will be logged.
      currentLogFilename: ../logs/reader/requests.log

      #  When the log file rolls over, the file will be archived to example-2012-03-15.log.gz,
      # example.log will be truncated, and new statements written to it.
      archivedLogFilenamePattern: ../logs/reader/requests-%d.log.gz

      # The maximum number of log files to archive.
      archivedFileCount: 5

    # Settings for logging to syslog.
    syslog:

      # If true, write log statements to syslog.
      enabled: false

      # The hostname of the syslog server to which statements will be sent.
      # N.B.: If this is the local host, the local syslog instance will need to be configured to
      # listen on an inet socket, not just a Unix socket.
      host: localhost

      # The syslog facility to which statements will be sent.
      facility: local0

让服务器等待而不响应空响应的参数是什么?

2 个答案:

答案 0 :(得分:1)

我明白了。这是这个参数

# HTTP-specific options.
http:

  # The maximum amount of time a connection is allowed to be idle before being closed.
  maxIdleTime: 60s

将时间延长到更长的时间,一切都很好。

答案 1 :(得分:1)

由于Dropwizard版本0.7及更高版本(使用当前0.9测试),配置已移至另一个参数:

server:
  applicationConnectors:
    - type: http
      ...
      idleTimeout: 60s

取自https://dropwizard.github.io/dropwizard/0.9.1/docs/manual/configuration.html#http

的文件
相关问题