Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  What is best to stock incoming messages : custom buffer pool or "new byte[n]" ?  (Read 2913 times)
0 Members and 1 Guest are viewing this topic.
Offline karmaGfa

Junior Duke




Miaow


« Posted 2006-02-13 05:54:10 »

Hello,

When our servers receives some variable sized messages that need to be stocked in a queue, what is the best practice to allocate some space where to put those messages :
- Simply to use the "new byte[n]" and let the JVM handle the memory,
- Or handle our own stack of buffers organized in a special-home-made way ? (if this is the best for performances, please explain how to handle them, please).

Karma.

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 818
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2006-02-13 09:02:02 »

if by buffers, you mean direct-byte-buffers, it's better to allocate a big one, and use duplicate it with smaller subranges. On Windows the minimum allocated size is 4k*, so a lot of tiny buffers would consume much more RAM than one split into pieces.

* got that from these forums - haven't checked it

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline karmaGfa

Junior Duke




Miaow


« Reply #2 - Posted 2006-02-13 10:48:35 »

I was thinking more about performances in terms of speed rather that memory usage, even if I still care about memory usage.

Note: The JVM is probably not using the allocation from Windows, so forget the 4k thing.

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Ninja


Medals: 52



« Reply #3 - Posted 2006-02-13 11:09:23 »

Hmm, I would let java handle the memory management as long as you don't have a critical performance problem. Maybe using Jakarta Collections is an option.

Once you have a problem, profile the application before trying an homemade alternative.

Mathias - I Know What [you] Did Last Summer!
Offline karmaGfa

Junior Duke




Miaow


« Reply #4 - Posted 2006-02-13 15:32:30 »

I can't do that, my program is a network library.

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Offline sunsett

Senior Duke




ribbit!


« Reply #5 - Posted 2006-02-13 17:37:14 »

What library is that?  I'm amazed at how many people write their own networking API.....it seems so counter-productive to me.   Shocked

I wish we could all just collaborate on one API and make it the best one with all the features anyone might need instead of having 50 mediocre ones.

-Matt Hicks
Offline Herkules

Senior Duke




Friendly fire isn't friendly!


« Reply #6 - Posted 2006-02-13 18:20:36 »

I guess http://jnag.dev.java.net  Grin

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline sunsett

Senior Duke




ribbit!


« Reply #7 - Posted 2006-02-13 18:40:15 »

Ya know....after a while those little signature bars just disapear from my vision....or maybe I just need glasses. :-p

Thanks for pointing that out Herkules. :-p
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2006-02-14 00:19:26 »

Traditionally this is done with ring buffers.

The nice things about a ring buffer are:
(a)Its memory usage is fixed and
(b)If it runs out of memory it starts by eliminate the oldest data.

There is no prebuilt Ring Buffer type in nio and whenever Ive tried to turn a Buffer into a ring buffer its seemed inordinately complex, so today id proably do it around an array though i WOULD like to solve the general case of wrapping ring logic around any Buffer subclass....

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline karmaGfa

Junior Duke




Miaow


« Reply #9 - Posted 2006-02-16 02:21:53 »

Can you describe a little more how your ring buffer is working ?

There is something to take into account, it is that in my case (JNAG) the messages are not  released in the same order that they are allocated since it is done by a pool of threads.

Karma

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2006-02-16 04:28:12 »

Can you describe a little more how your ring buffer is working ?

There is something to take into account, it is that in my case (JNAG) the messages are not  released in the same order that they are allocated since it is done by a pool of threads.

Karma

hrm.

If its not a FIFO queue then a ring buffer wont work.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline karmaGfa

Junior Duke




Miaow


« Reply #11 - Posted 2006-02-16 13:44:30 »

I saw that mina (the project from Apache) is using a home-made pool of buffers implemented in the org.apache.mina.common.ByteBuffer.
I will take a look at it asap, it seems to be made for the case of JNAG (i.e. multi thread processing the messages Grin).

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Offline karmaGfa

Junior Duke




Miaow


« Reply #12 - Posted 2006-02-16 17:30:24 »

What library is that?  I'm amazed at how many people write their own networking API.....it seems so counter-productive to me.   Shocked

Hey ! You spoke about JNAG when you proposed your project and now you don't know what it is ? Huh
You also forgot about me ? I gave my "yes" for your project when you proposed it, putting the emphasis on more choice for the community.

I wish we could all just collaborate on one API and make it the best one with all the features anyone might need instead of having 50 mediocre ones.

-Matt Hicks

By posting some questions here in the forum about some precise details of the implementations of network libraries, I am also hoping to contribute to help the other libraries to improve.

By the way, the 50 guys that try hard to make their library say thank you to you for your moral support. Just a stupid question : What makes you believe that your library is better than the other ones ? Is it because it is a library that you wrote ? And to enlight your curiosity, I started my library because I don't like the existing ones and I continue it because I still don't like the existing ones. That's also probably the same for the 50 others that you are speaking about.

Karma

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #13 - Posted 2006-02-16 19:21:55 »

Traditionally this is done with ring buffers.
...
There is no prebuilt Ring Buffer type in nio and whenever Ive tried to turn a Buffer into a ring buffer its seemed inordinately complex

Yes! And ... I logged a bug against NIO for this over a year ago Sad. It's ridiculous trying to do serious buffer-based I/O without ring buffers Sad.

malloc will be first against the wall when the revolution comes...
Offline karmaGfa

Junior Duke




Miaow


« Reply #14 - Posted 2006-02-17 01:08:01 »

Yes! And ... I logged a bug against NIO for this over a year ago Sad.

What's his ID number ? I want to take a look at it.

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (20 views)
2014-10-25 15:46:29

Longarmx (53 views)
2014-10-17 03:59:02

Norakomi (47 views)
2014-10-16 15:22:06

Norakomi (35 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (69 views)
2014-10-14 00:35:47

TehJavaDev (61 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (46 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!