Java 服务器端应用程序,如何?

发布于 2024-08-12 08:26:27 字数 440 浏览 5 评论 0原文

我正在用 Java 构建一个可扩展的服务器端应用程序,但我需要知道“该做什么和不该做什么”。

该应用程序需要客户端通过 TCP 套接字连接到服务器,我听说过很多关于 Apache MINA 的好消息,所以我想我应该尝试一下并围绕它进行构建。我还需要该应用程序与数据库进行通信,并根据请求或推送向客户端发送合适的数据。

我会管理自己的家庭服务器,这样即使是在我的控制之下。

我对以下问题有一些疑问:

  • 服务器端是否需要有一个 GUI,报告状态、连接 和例外情况。如果是这样我该怎么办 实现这个,我应该使用 Swing 吗?
  • MINA 正在处理连接,但是 我如何处理数据库(MySQL)?
  • 我如何测试这个应用程序 可扩展性,我该如何模拟 客户端与服务器的连接。
  • 有没有什么框架可以做到 以上所有内容还是我必须 处理好各个方面。

I am building a scalable Server Side App in Java but I need to know the "Do's and the Dont's".

The app needs clients to connect to the server via TCP Sockets, I heard lot of good things about Apache MINA so I thought I'd give it a try and build around this. I would also need the app to communicate to a Database and send suitable data to the clients either on request or push.

I would me managing my own home server so even that would be under my control.

I have some doubts about the following:

  • Does a Server side need to have a
    GUI, to report status, connectivity
    and exceptions. If so how do I
    implement this, should I use Swing?
  • MINA is handling the connectivity but
    how do I handle the database(MySQL)?
  • How could I test this app for
    scalability, how can I simulate
    client connections to the server.
  • Is there any framework that can do
    all of the above or do I have to
    handle each aspect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不知在何时 2024-08-19 08:26:27

我如何测试这个应用程序
可扩展性,我如何模拟客户端
与服务器的连接。

对于可扩展性测试,我建议使用 Apache JMeter。它是一个优秀、免费且相当简单的工具,用于创建和测量应用程序的负载。您可以获得有关响应时间、每秒事务数、服务器负载等的信息。

我在 HTTP 应用程序中经常使用它。对于您的 TCP 应用程序,它有一个 TCP Sampler,但使用您已经编写的连接代码为其 Java Sampler 创建实现可能会更容易。我还建议将其与 rstatd 采样器插件 结合使用,以便您可以在测试期间测量服务器 CPU/内存。

熟悉这个工具可能需要几天的时间,但它对我来说非常有用。

服务器端是否需要有 GUI,
报告状态、连接性和
例外。

老实说,服务器端的 GUI可能有点大材小用。当然,如果有某种带有一堆闪烁的红灯和绿灯以及滚动日志的控制台就好了,但归根结底,这些都只是 YAGNI 的东西。

只要您的服务器正在为您想要跟踪的事务和事件写入日志和审核信息,就足够了。拥有 GUI 只会增加服务器的复杂性,可能会产生更多错误。另外,如果您有效地使用日志,则可以插入其他监视/警报机制(例如 SNMP)。

如何处理数据库(MySQL)?

其他答案有一些很好的建议;这个话题本身可能就已经被更好地涵盖了,并且已经有很多关于它的问题被问到。我建议对 ORM+Java 进行一些搜索以获得一些好的意见。这里有一些不错的链接:

您可以找到对所有不同 ORM 的不同意见,以及根本不使用它们的拥护者。我本身没有意见——在研究了各种选项后,只需使用你认为适合这份工作的东西即可。

有没有什么框架可以做到这一切
上述情况还是我必须处理
每个方面。

值得怀疑,如果有的话,它可能太通用了,无论如何你最终都会为它编写一堆代码。对于 ORM + GUI(如果您确实使用 GUI),有一些在 JVM 上运行的开箱即用的 MVC+数据库 Web 解决方案,例如 Grails.但您的大多数问题涉及不同的问题领域,每个问题都需要自己单独的解决方案。

How could I test this app for
scalability, how can I simulate client
connections to the server.

For the scalability testing, I'd recommend Apache JMeter. It's an excellent, free, and fairly straightforward tool for creating and measuring load on your application. You can get information about response times, transactions per second, server load, etc.

I've used it quite a bit with HTTP applications. For your TCP application, it has a TCP Sampler, but it would probably be easier to create an implementation for its Java Sampler using connectivity code you've already written. I'd also recommend combining it with the rstatd sampler plugin so you can measure server CPU/memory during the test.

It may take a couple days to get familiar with the tool, but it has served me pretty well.

Does a Server side need to have a GUI,
to report status, connectivity and
exceptions.

Honestly, a GUI for the server side is probably overkill. Sure, it'd be neat to have some sort of console that has a bunch of flashing red and green lights and scrolling logs, but when it comes down to it, those are all just YAGNI items.

As long as your server is writing logs and audit information for the transactions and events you want to follow, that's sufficient. Having a GUI will just add to the complexity of the server, likely yielding more bugs. Plus, if you're using logs effectively, you can plug into other monitoring/alerting mechanisms (SNMP, for example).

how do I handle the database(MySQL)?

The other answers have some good suggestions; this is a topic probably better-covered on its own, and there have been many questions asked about it. I'd recommend doing some searches for ORM+Java to get some good opinions on it. Here are a few decent links:

You can find varying opinions on all of the different ORMs, as well as advocates of not using them at all. I don't have an opinion, per se - just use what you feel is appropriate for the job after researching the options.

Is there any framework that can do all
of the above or do I have to handle
each aspect.

Doubtful, and if there is, it's probably so generic you'll end up writing a bunch of code for it anyway. For the ORM + GUI (if you do go with the GUI), there are out-of-the-box MVC+database web solutions that run on the JVM like Grails. But most of your questions involve different problem domains, each needing its own separate solution.

桜花祭 2024-08-19 08:26:27

服务器端是否需要有一个 GUI 来报告状态、连接和异常。如果是这样,我该如何实现这个,我应该使用 Swing 吗?

您不必有 GUI 端,您可以将日志写入文件,或使用其他日志服务器,例如 Windows 事件日志。

MINA 正在处理连接,但我如何处理数据库(MySQL)

有大量不同的方法可以访问 MySQL 数据库,我确信 swing 对此有一个框架。您也可以尝试 hibernate,它类似于 .NET 中的 LINQ,但适用于 Java。

如何测试此应用程序的可扩展性,如何模拟客户端与服务器的连接。

您需要一个测试框架,尝试 JUnit。

Does a Server side need to have a GUI, to report status, connectivity and exceptions. If so how do I implement this, should I use Swing?

You don't have to have GUI side, you can just write a log to a file, or use some other logging server, like windows event log.

MINA is handling the connectivity but how do I handle the database(MySQL)

There are tons of different ways to access your MySQL database, I'm sure swing, has a framework for this. Also you can try hibernate, which is like LINQ in .NET but for Java.

How could I test this app for scalability, how can I simulate client connections to the server.

You'll need a testing framework for that, try JUnit.

澜川若宁 2024-08-19 08:26:27

MINA 是一个优秀的框架。

  • 服务器端是否需要有 GUI 来报告状态、连接和异常。如果是这样,我该如何实现这个,我应该使用 Swing 吗?

简短回答:不!
长答案:服务器通常没有 GUI,因为大多数大型服务器系统甚至根本没有显示器。更好的解决方案是使用JMX来提供统计信息。 MINA 已经预定义了 MBean,您只需将其添加到 JMX 服务中即可。使用 JMX 客户端,您可以访问这些信息并构建 GUI。
只需尝试 JConsole 并选择一个本地 java 应用程序即可了解它。

  • MINA 正在处理连接,但我如何处理数据库(MySQL)?

处理数据库的方法有很多种。纯 JDBC、Hibernate 或其他 ORM 框架。只要确保您使用的东西是线程安全的!

  • 如何测试此应用的可扩展性,如何模拟客户端与服务器的连接。

要么编写一个简单的客户端并启动它数千次,要么使用专门的测试框架。如果您使用的是现有协议,那么可能有一个特定的协议。

  • 是否有任何框架可以完成上述所有操作,或者我必须处理每个方面。

取决于协议和您想要实现的目标。有一个基于 MINA 的 FTP 服务器,它可以完成所有功能,但这是一种特定的实现,无法满足您的需求。
如果您使用自己的协议,则必须自行实现编码/解码器以及协议和消息的处理。这包括在数据库中存储消息信息。

MINA is an excellent framework.

  • Does a Server side need to have a GUI, to report status, connectivity and exceptions. If so how do I implement this, should I use Swing?

Short Answer: No!
Long Answer: A server normaly doesn't have a GUI, because most of the big server systems doesn't even have a display at all. A better solution is to use JMX to provide statistics. MINA has predefined MBeans which you only have to add to the JMX service. With a JMX-Client you can access these informations and build a GUI.
Just try the JConsole and choose a local java application to get an idea about it.

  • MINA is handling the connectivity but how do I handle the database(MySQL)?

There are many ways to handle the database. Either pure JDBC, Hibernate or another ORM framework. Just make sure, that the thing you are using is thread safe!

  • How could I test this app for scalability, how can I simulate client connections to the server.

Either write a simple client and start it some thousand times, or use a specialized testing framework. If you are using an existing protocol, then there may be a specific one for that.

  • Is there any framework that can do all of the above or do I have to handle each aspect.

Depends on the protocol and what you want to achieve. There is an FTP server based on MINA which does all in one, but that's a specific implementation and won't fit on your needs.
If you are using your own protocol, you have to implement en-/decoders and the handling of protocol and messages on your own. This includes the storage of message informations at the database.

辞旧 2024-08-19 08:26:27
  • 如果您认为这对您很重要
    申请举报事情
    你提到的,你可能
    应该。您可以使用 Swing 作为 GUI。如果
    你在网络方面更有经验
    发展,你也可以让你的
    服务器应用程序写入数据库,
    并将其显示在网页上(并且
    也可以用另一种方式写,通过
    数据库)。你所做的选择
    应该基于您的想法
    应用程序将会发展。

  • 如果您的数据库操作受到限制,您可以只使用普通的旧 JDBC 库,它将为您提供对 MySQL 数据库执行写入/读取操作所需的类。如果您认为您的应用程序的大小/复杂性会在某种程度上增加,您可能需要考虑 ORM 某种类型(例如 Hibernate)。

  • 我读到 JMeter 是一个用于在客户端-服务器设置中测试客户端负载的工具。我自己没有尝试过这个。 JUnit 不会帮助您测量这一点。

  • If you think it's important for your
    application to report the things
    you're mentioning, you probably
    should. You can use Swing as GUI. If
    you're more experienced in web
    development, you could also make your
    server app to write to the database,
    and display this on a web page (and
    also write the other way, via the
    database). The choices you make
    should be based on how you think your
    application would evolve.

  • If your database operations is limited, you can just use the plain old JDBC library, which will provide you with the classes you need to perform writes/reads to/from the MySQL database. If you think your application will grow in size/complexity to some degree, you may want to consider an ORM of some kind (Hibernate for example).

  • I've read that JMeter is a tool for testing client load in a client-server setting. I've not tried this myself. JUnit won't help you in measuring this.

温柔女人霸气范 2024-08-19 08:26:27
  • 服务器端是否需要有 GUI 来报告状态、连接和异常。如果是这样,我该如何实现这个,我应该使用 Swing 吗?

不,没必要。异常应该记录在日志文件中。当客户请求时,可以在简单的控制台中报告状态。还有连接信息。换句话说,(Swing)GUI 可能很方便,但无论如何你都应该从低级的东西开始,而且它是一个低优先级的功能,拥有它就好了。

  • MINA 正在处理连接,但我如何处理数据库 (MySQL)?

我不知道这个问题是关于数据库连接还是数据库访问。如果涉及数据库访问,则根据您要做的事情的复杂性和 OO 性,ORM 可能是个好主意,也可能不是,在这种情况下您可能更喜欢原始 JDBC。如果没有更多细节,就无法回答。如果是关于数据库连接处理,也许使用像 c3p0 这样的连接池,但忘记 JNDI。

  • 如何测试此应用的可扩展性,如何模拟客户端与服务器的连接。

为此,正如其他答案中所建议的,JMeter 及其 TCP 采样器将完成这项工作。

  • 是否有任何框架可以完成上述所有操作,或者我必须处理每个方面。

正如我所说,如果没有更多细节,就不可能给出更具体或更准确的答案。

  • Does a Server side need to have a GUI, to report status, connectivity and exceptions. If so how do I implement this, should I use Swing?

No, it doesn't have to. Exceptions should go in a log file. Status could be reported in a simple console when requested by a client. And connectivity informations too. In other words, a (Swing) GUI could be handy but you should start with low level stuff anyway and it is a low priority feature, just nice to have.

  • MINA is handling the connectivity but how do I handle the database (MySQL)?

I don't know if this question is about database connections or database access. If it's about database access, depending on the complexity and the OOness of what you'll be doing, an ORM might be good idea, or not, in which case you might prefer raw JDBC. Without more details, it's impossible to answer though. If it's about database connections handling, maybe use a connection pool like c3p0 but forget JNDI.

  • How could I test this app for scalability, how can I simulate client connections to the server.

For this, as suggested in other answers, JMeter and its TCP sampler will do the job.

  • Is there any framework that can do all of the above or do I have to handle each aspect.

As I said, without more details, it's impossible to give more specific or precise answers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文