开发者

Java Server Side App, How to?

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 pus开发者_StackOverflowh.

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.


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:

  • what-java-orm-do-you-prefer-and-why
  • hibernate-ibatis-jee-or-other-java-orm-tool

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.


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.


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.


  • 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.


  • 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜