views:

173

answers:

5

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.
+2  A: 

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.

Haim Bender
Apache MINA already uses the SL4J logging framework is that sufficient? I don't know much about Windows Event Log.
Kevin Boyd
SL4J is perfectly fine. And since you are doing Java, don't bother with MS specific things.
Pascal Thivent
+1  A: 
  • 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.

Yngve Sneen Lindal
Writing some logs to the Database seems to be a good idea as I said earlier I haven't done things like this before so I need to gather some info to get stable. Could you suggest some good reading material for building a scalable Java server side app.Also since clients would be connected via sockets some one suggested to use JNDI datasource connection pool for database connections. I will have a look at Hibernate.
Kevin Boyd
Is this a J2EE (Java Enterprise Edition) application? Or are you using plaing J2SE?
Yngve Sneen Lindal
Since I am using sockets I am using J2SE, do you think J2EE is better suited for this kind of app?
Kevin Boyd
No, not necessarily. It seems like MINA takes care of the "hard" parts of achieving scalability (threading and so on..) (which J2EE also does).
Yngve Sneen Lindal
What J2EE container would you suggest for this kind of application?
Kevin Boyd
I've only worked with Glassfish (Sun) which is the reference implementation. The only reason for using J2EE in your case (based on the information provided) must be database connection pooling. You could search on the topic "glassfish jndi connection pooling" or something. I don't know how well J2EE and MINA works with each other, but as I said, sockets is also possible in J2EE. I've used connection pooling in Glassfish, and it is quite easy to set up.
Yngve Sneen Lindal
I think Glassfish has the Grizzly component to do that (handle sockets), not yet decided what to go for though J2SE or J2EE.
Kevin Boyd
+2  A: 

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.

Rob Hruska
Is Hibernate J2SE or a J2EE container, Can I go in for jdbc with c3p0 for connection pooling as Pascal Thivent suggested, will that scale well enough?
Kevin Boyd
Sorry I didn't thank you for a well explained answer! Thanks!!
Kevin Boyd
No problem. As for scaling, depends on how much you need. Your question doesn't really specify how much load you need to support. Either solution (Hibernate or straight JDBC + c3p0) will probably scale just fine. I haven't used c3p0, though, so I can't say for sure. Also, Hibernate's not a container, it's a library. It does work with any decent J2EE container, though.
Rob Hruska
+1  A: 
  • 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.

Pascal Thivent
What other details do you need?
Kevin Boyd
Things like what is your application going to do, what are representative use case, what data are you going to manipulate, how much, etc.
Pascal Thivent
+1  A: 

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.

Hardcoded