1

我将告诉我必须解决的问题,如果我走在正确的道路上,我需要一些建议。

问题是:

我需要创建一个接收请求并执行某些操作的 Windows 服务应用程序。(Socket通信)这个动作是执行一个脚本(可能是lua或perl)。这个脚本模拟客户端的业务规则,在数据库中查询,在网站中发出请求,然后向客户端发送响应。

有3个强制性要求:

  1. 该服务会同时收到大量请求。所以我想用worker的线程模型。
  2. 该服务必须具有高吞吐量。我将在同一秒内收到许多请求。
  3. 低延迟:我必须非常快速地响应这些请求。

每个请求都会生成一个日志条目。由于 I/O 时间过长,我无法在脚本执行的同时将这些日志条目写入物理磁盘。可能我会在内存中创建一个队列,其他线程将消耗这个队列并写入磁盘。

将来,两个woker的线程可能要更改消息。

我必须为此服务制定协议。我正在考虑使用 Thrift,但我不知道所涉及的开销。也许我会制定自己的协议。

要编写 Windows 服务,我正在考虑使用 Erlang。这是个好主意吗?

有没有人有解决这个问题的建议/提示?编写此服务的最佳语言是哪种?

4

1 回答 1

1

Yes, Erlang is a good choice if you're know it or ready to learn. With Erlang you don't need any worker thread, just implement your server in Erlang style and you'll receive multithreaded solution automatically.

Not sure how to convert Erlang program to Windows service, but probably it's doable.

Writing to the same log file from many threads are suboptimal because requires locking. It's better to have a log-entries queue (lock-free?) and a separate thread (Erlang process?) that writes them to the file. BTW, are you sure that executing external script in another language is much faster than writing a log-record to the file?

It's doubtfully you'll receive much better performance with your own serialization library than Thrift provides for free. Another option is Google Protocol Buffers, somebody claimed that it's faster.

Theoretically (!) it's possible that Erlang solution won't provide you required performance. In this case consider a compilable language, e.g. C++ and asynchronous networking, e.g. Boost.Asio. But be ready that it's much more complicated than Erlang way.

于 2011-04-02T17:25:34.063 回答