【问题标题】:dropwizard jetty server request timeoutdropwizard码头服务器请求超时
【发布时间】:2015-07-24 21:18:23
【问题描述】:

我有一个基于 dropwizard 的网络服务。有一个请求应该需要很长时间,请求客户端应该等待服务器响应。但我观察到的是,即使在应用程序可以处理请求之前,服务器就已经响应了请求。这是 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

我可以给什么参数让服务器等待而不响应空响应?

【问题讨论】:

  • 我会尝试使用像 tcpdump 或 fiddler 这样的网络跟踪工具来调试它。不知何故,您对 localhost 的请求没有命中您的应用程序服务器
  • 这不是真的,我在为请求提供服务的方法中放置了一个调试点,并且调试器在断点处中断。

标签: jetty dropwizard


【解决方案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的文档

【讨论】:

【解决方案2】:

我想通了。就是这个参数

# HTTP-specific options.
http:

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

将其增加到更长的时间,一切都很好。

【讨论】:

  • 此答案适用于 Dropwizard
猜你喜欢
  • 2011-07-23
  • 1970-01-01
  • 2021-11-25
  • 2015-08-27
  • 2016-08-19
  • 2016-05-16
  • 1970-01-01
  • 1970-01-01
  • 2018-11-09
相关资源
最近更新 更多