Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message Buffer Issue. #2

Open
hassanfarrukh opened this issue Feb 25, 2016 · 4 comments
Open

Message Buffer Issue. #2

hassanfarrukh opened this issue Feb 25, 2016 · 4 comments

Comments

@hassanfarrukh
Copy link

Hellio Jjenkov,
I was using your server, I like the way you have coded it but there is an issue I found out when I bombarded the server with multiple clients. It can receive the total of 512 messages.

Furthermore, I found out that if I change the size of:
public static int KB = Constant.maxLimit; public static int MB = Constant.maxLimit * KB; byte[] smallMessageBuffer = new byte[Constant.maxLimit * 4 * KB]; QueueIntFlip smallMessageBufferFreeBlocks = new QueueIntFlip(Constant.maxLimit);

The maxLimit is:

public class Constant { public static int maxLimit = 2048; }

In Server Class

Queue socketQueue = new ArrayBlockingQueue(Constant.maxLimit);

In SocketProcessor

private ByteBuffer readByteBuffer = ByteBuffer.allocate(Constant.maxLimit * Constant.maxLimit); private ByteBuffer writeByteBuffer = ByteBuffer.allocate(Constant.maxLimit * Constant.maxLimit); private double nextSocketId = 16 * Constant.maxLimit;

The client code I am using is:

client = SocketChannel.open(); isa = new InetSocketAddress("127.0.0.1", 9998); client.connect(isa); client.configureBlocking(false); sendMessage(); //here i send PING. client.close(); try { Thread.sleep(500); } catch (InterruptedException ex) { Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); }

Please reply to the issue and help me accordingly.

@hassanfarrukh
Copy link
Author

This was the error:
Exception in thread "Thread-1" java.lang.NullPointerException at SmartCity.HttpMessageReader.read(HttpMessageReader.java:51) at SmartCity.SocketProcessor.readFromSocket(SocketProcessor.java:134) at SmartCity.SocketProcessor.readFromSockets(SocketProcessor.java:121) at SmartCity.SocketProcessor.executeCycle(SocketProcessor.java:81) at SmartCity.SocketProcessor.run(SocketProcessor.java:65) at java.lang.Thread.run(Thread.java:745)

@jjenkov
Copy link
Owner

jjenkov commented Feb 26, 2016

I'll have a look at it - but I have used this design to send millions of messages to a server without a single hickup. To be fair though, I was using IAP as network protocol instead of HTTP. Seeing that your error occurs in the HttpMessageReader hints that this might be where the issue is hidden.

@jjenkov
Copy link
Owner

jjenkov commented Feb 26, 2016

Oh, it will take me at least 1-2 weeks before I have time to look into it... please see if you can find out what the error is yourself too, and if you do, please let me know!

@hassanfarrukh
Copy link
Author

First of I am using this Server as a TCP server. I have worked, it might be a solution but I am not sure, as it gave birth to a new issue, which I couldn't resolve yet!

In MessageBuffer class I commented return null and it resolved more socket generation issue;

public Message getMessage() {
int nextFreeSmallBlock = this.smallMessageBufferFreeBlocks.take(); if(nextFreeSmallBlock == -1)
{
// return null;
}
Message message = new Message(this); //todo get from Message pool - caps memory usage. message.sharedArray = this.smallMessageBuffer; message.capacity = CAPACITY_SMALL; message.offset = nextFreeSmallBlock; message.length = 0; return message;
}

As mentioned earlier this gave birth to a new issue; when we send simultaneous messages at the same time otherwise it works okay. And the issue is in Message Class here;
public int writeToMessage(byte[] byteArray, int offset, int length)

System.arraycopy(byteArray, offset, this.sharedArray, this.offset + this.length, bytesToCopy);

And this gives an error of out of array index. I will post the error as soon as I regenerate this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants