Search code examples
javaperformancebenchmarkingrmikryo

Custom network library and serialzation VS default Serialization and RMI


I have this class, I m sending this class via RMI and via kryonet and kryo, I m getting the array of 10 objects with both incase of rmi, as return of remote method call and in case of kryonet echoing from server to client with kryonet and kryo, I have total of one object 55*10 which 555 but with RMI 1196bytes ,

Are these results are reasonable?, can some body shed some light,

*why these results are like that?

why there is that much difference.?

which overheads or other factors are involved behind the scene,

which are making that much total in RMI and too much difference and point me.

And is it 55 bytes total for single object is ok?*.

i just need some confirmation and experts eyes as i have to present these results,

I will be really thankful.

This is class which I m using with both:

public class TBall {

private float x, y; // Ball's center (x, y)
private float speedX, speedY; // Ball's speed per step in x and y
private float radius; // Ball's radius
private Color color; // Ball's color

public boolean collisionDetected = false;
public static boolean run = false;

private String name;

private float nextX, nextY;
private float nextSpeedX, nextSpeedY;

public TBall() {
    super();
}

public TBall(String name1, float x, float y, float radius, float speed,
        float angleInDegree, Color color) {
    this.x = x;
    this.y = y;
    // Convert velocity from polar to rectangular x and y.
    this.speedX = speed * (float) Math.cos(Math.toRadians(angleInDegree));
    this.speedY = speed * (float) Math.sin(Math.toRadians(angleInDegree));
    this.radius = radius;
    this.color = color;
    this.name = name1;
}

public String getName() {
    return this.name;
}

public float getSpeed() {
    return (float) Math.sqrt(speedX * speedX + speedY * speedY);
}

public float getMoveAngle() {
    return (float) Math.toDegrees(Math.atan2(speedY, speedX));
}

public float getRadius() {
    return radius;
}

public Color getColor() {
    return this.color;
}

public void setColor(Color col) {
    this.color = col;
}

public float getX() {
    return x;
}

public float getY() {
    return y;
}

public void setX(float f) {
    x = (int) f;
}

public void setY(float f) {
    y = (int) f;
}

public void move() {
    if (collisionDetected) {
        // Collision detected, use the values computed.
        x = nextX;
        y = nextY;
        speedX = nextSpeedX;
        speedY = nextSpeedY;
    } else {
        // No collision, move one step and no change in speed.
        x += speedX;
        y += speedY;
    }
    collisionDetected = false; // Clear the flag for the next step

    System.out.println("In serializedBall in move.");
}

public void collideWith() {

    float minX = 0 + radius;
    float minY = 0 + radius;
    float maxX = 0 + 640 - 1 - radius;
    float maxY = 0 + 480 - 1 - radius;

    double gravAmount = 0.9811111f;
    double gravDir = (90 / 57.2960285258);

    // Try moving one full step
    nextX = x + speedX;
    nextY = y + speedY;
    System.out.println("In serializedBall in collision.");

    // If collision detected. Reflect on the x or/and y axis
    // and place the ball at the point of impact.
    if (speedX != 0) {
        if (nextX > maxX) { // Check maximum-X bound
            collisionDetected = true;
            nextSpeedX = -speedX; // Reflect
            nextSpeedY = speedY; // Same
            nextX = maxX;
            nextY = (maxX - x) * speedY / speedX + y; // speedX non-zero
        } else if (nextX < minX) { // Check minimum-X bound
            collisionDetected = true;
            nextSpeedX = -speedX; // Reflect
            nextSpeedY = speedY; // Same
            nextX = minX;
            nextY = (minX - x) * speedY / speedX + y; // speedX non-zero
        }
    }
    // In case the ball runs over both the borders.
    if (speedY != 0) {
        if (nextY > maxY) { // Check maximum-Y bound
            collisionDetected = true;
            nextSpeedX = speedX; // Same
            nextSpeedY = -speedY; // Reflect
            nextY = maxY;
            nextX = (maxY - y) * speedX / speedY + x; // speedY non-zero
        } else if (nextY < minY) { // Check minimum-Y bound
            collisionDetected = true;
            nextSpeedX = speedX; // Same
            nextSpeedY = -speedY; // Reflect
            nextY = minY;
            nextX = (minY - y) * speedX / speedY + x; // speedY non-zero
        }
    }

    System.out.println("In serializedBall collision.");
    // speedX += Math.cos(gravDir) * gravAmount;
    // speedY += Math.sin(gravDir) * gravAmount;

    System.out.println("In serializedBall in collision.");
}

}

Thanks.


Solution

  • Where did you get '55' from? You have:

    9 floats, = 9x4 bytes, total 36 bytes 1 boolean, serialized as a byte, total 1 byte 1 String, could be any length 1 Color, which in turn contains: 1 int, serialized as 4 bytes 1 float, serialized as 4 bytes 2 float[] of length 3 each, serialized as 24 bytes 1 Colorspace, which in turn contains: 2 ints, serialized as 8 bytes

    The total of this is at least 77 bytes plus whatever is required to transmit the String.

    Serialization also sends class information, versioning information, and a tag in front of every item; RMI also sends method information. All that could easily account for the difference. I don't know what those other packages do.