Datagram Socket & Datagram Channel performance

Hi,<br>
<br>
I have been writing a video streaming server, and i have found that it does not perform anywhere near how it should (with available disk and network bandwidth). I have split the program down, and discovered that sending UDP packets appears to be running really slowly. Here is an example of the code i am using (sending blank packets for speed).<br>
<br>
<code>
while (totalBytesSent < 150000000)<br>
{<br>
totalBytesSent += (188 * 7);<br>
udpPacket.setData(payload);<br>
udpPacket.setAddress(InetAddress.getByName("239.2.1.10"));<br>
udpPacket.setPort(23232);<br>
udpSocket.send(udpPacket);<br>
}<br>
</code>
<br>
it sends 150 megs of data in about 30 seconds = 5 meg/sec which is no where near the available bandwidth (gigabit lan).<br>
<br>
So, i thought maybe the NIO packages are the solution, but i get similar performance using the datagram channel and byte buffers with this code:<br>
<br>
<code>
while (totalBytesSent < 160000000)<br>
{<br>
inStream.read(fileBuf);<br>
buffer.put(fileBuf);<br>
buffer.flip();<br>
bytesSent += udpChannel.send(buffer, destAddress);<br>
buffer.position(0);<br>
totalBytesSent += (188*7);<br>
}<br>
</code>
<br>
what am i doing wrong? is there a better way of sending data over a network? what I am essentially doing is trying to read directly from a file on the disk and send it straight over the network as fast as possible. Any help much appreciated.<br>
<br>
Cheers<br>
<br>
Robert Clarkson<br>

I don't know where your performance is going now, but you're in danger of not even sending all the data with this code.
The canonical form of the NIO copying loop is:<br>
<code><br>
while (rdr.read(buffer) > 0 || buffer.position() > 0)<br>
{<br>
buffer.flip();<br>
bytesSent += udpChannel.send(buffer,destAddress);<br>
buffer.compact();<br>
}<br>
</code><br>
Your version assumes the write was complete; this doesn't. The write can return zero for example, in which case the data will just be lost in your version. Maybe that's where your throughput is going?
or OTOH does the computer you're running this on have more than 1 NIC? and if so is one slower than the other? You can see where I'm going with this.

Similar Messages

  • Socket based application - Performance Issues - Suggestions Needed

    Hi All,
    We have an application which basically has been developed using core java. Here is a high level information about the application:
    a) It opens a serversocket which allows clients to connect to it.
    b) For every new client connection, a separate thread is created and this thread deals with requests from clients, processing the data and replying back to clients.
    c) Each socket is polled continuously and sockettimeout is 2 seconds. If there is a timeout, we handle the situation and socket is again read. So basically sockets is read every 2 seconds. If number of timeouts reaches a configurable value, we close the connection and thread is dropped as well.
    d) In production, three instances of this application are running with the help of a cisco load balancer. It is there for last 5 years.
    However there has always been some minor performance isssues and we have sorted them out using different types of garbage collectors, by introducing hardware load balancers, upgrading the code for new Java versions. It is currently running on 1.4.2.
    However there has always been some performance issues and today while googling over internet I came across following on the bea website which says that core java sockets are not as efficients as native API. BEA has implemented its own APIs for weblogic. My queries are:
    a) Are there any better Java Socket/network API (for solairs, I know Java is plateform independenet but there could be lib which also using native libs) which are much more efficient than Core Java.
    b) We are getting the InputStream/OutputStream and creating objects of DataInputStream/DataOutputStream to read the data 'Byte-By-Byte'. Each byte can have different information thats why it is required. Are there any better way of getting info than what we are currently doing.
    c) As I mentioned, we are continously polling the socket for read operation with a timeout value of 2 seconds. What is the better among the following from performance point of view: (1) Frequent read operation with a lesser timeout value or (2) Less Frequent read operations with larger timeout value. (3) Any better idea??
    Please suggest few things or pointers which I could do to improve the performance of the applcations. Many thanks.
    Thanks,Akhil
    From BEA website:-
    "Although the pure-Java implementation of socket reader threads is a reliable and portable method of peer-to-peer communication, it does not provide the best performance for heavy-duty socket usage in a WebLogic Server cluster. With pure-Java socket readers, threads must actively poll all opened sockets to determine if they contain data to read. In other words, socket reader threads are always "busy" polling sockets, even if the sockets have no data to read. This unnecessary overhead can reduce performance."

    My recommendations:
    - Always use a BufferedInputStream and BufferedOutputStream around the socket streams
    - Increase the socket send and receive buffers to at least 32k if you are on a Windows platform where the default is a ridiculous 8k, which hasn't been enough for about 15 years.
    - Your 2-second timeout is far too short. Increase it to at least 10 seconds.
    - Your strategy of counting up to N short timeouts of S seconds each is completely pointless. Change it to one single timeout of N*S seconds. There is nothing to be gained by the complication you have introduced to this.

  • RFC comunication channel performance

    Hi All,
      My clients business will have inflow of huge messages and frequency is also more , As far as the performnace is concerned while using RFC lookups .which one of the below options is better while performance tuning ?.
    1. Creating RFC communicatoin channels invidual interfaces for RFC lookup .
    or
    2. Using single RFC communication channel for all RFC lookups .
    Do suggest me and add your valuable points .
    Thanks,
    Amar.

    Which Version of PI you are working on, 3.0 / 7.0 / 7.1  ?
    if 3.0 go for separate RFC lookups, since your customer's need is to handle huge data and more frequent data the RFC adapter might face 'Timed out' issue if you use single RFC Connection.
    rest of the versions i'm not sure.
    Thanks,
    Saravanan N

  • Sockets and Channels?

    Hi,
    I have just completed the chapter about 'Channels' in the book I am reading. I was completely new to these since I had never seen them or heard of them before! Thus I am feeling quite confused on when these should be used and why!
    Basically each time I asked networking question I always got the same answer, that is 'sockets'. Socket programming is quite strait forward in Java and in my opinion not that much complicated. However Channels, which for me are completely new, seem to be very complicated! Also it seem that I can achieve with Sockets all that I can achieve with Channels with the only difference of 'non-Blocking' which I do understand, but maybe on giving it the just amount of importance!
    Thanks for any comments,
    Regards,
    Sim085

    I'm not all too good with NIO (Channels) but I think I can answer you.
    Channels are event driven, so no need for a separate thread to wait for connections (lots of waiting), one thread per a connection to do the communication (and generally do a lot of waiting) etc. Everything can be done in one thread, selector will pick the proper channel when an event occurs. Also, sometimes you might need non-blocking reads, as you said you can't achieve those with Sockets.
    ...someone correct/fill me if I said anything wrong/incomplete....

  • CORBA (Parlay) socket or channel connection exception

    We've been encountering the following exception in our parlay framework gateway application:
    Oct 17, 2006 7:23:20 AM com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase readGIOPHeader
    FINE: "IOP00410211: (COMM_FAILURE) IOException when reading connection"
    org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 211  completed: No
            at com.sun.corba.se.impl.logging.ORBUtilSystemException.ioexceptionWhenReadingConnection(ORBUtilSystemException.java:2456)
            at com.sun.corba.se.impl.logging.ORBUtilSystemException.ioexceptionWhenReadingConnection(ORBUtilSystemException.java:2474)
            at com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase.readGIOPHeader(MessageBase.java:116)
            at com.sun.corba.se.impl.transport.CorbaContactInfoBase.createMessageMediator(CorbaContactInfoBase.java:150)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.readBits(SocketOrChannelConnectionImpl.java:314)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.handleEvent(SocketOrChannelConnectionImpl.java:1098)
            at com.sun.corba.se.impl.transport.SelectorImpl.run(SelectorImpl.java:282)
    Caused by: java.io.IOException: End-of-stream
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.readFully(SocketOrChannelConnectionImpl.java:602)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.read(SocketOrChannelConnectionImpl.java:521)
            at com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase.readGIOPHeader(MessageBase.java:112)
            ... 4 more
    Oct 17, 2006 7:23:20 AM com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl readBits
    FINE: "IOP00410208: (COMM_FAILURE) Connection abort"
    org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 208  completed: No
            at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectionAbort(ORBUtilSystemException.java:2372)
            at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectionAbort(ORBUtilSystemException.java:2390)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.readBits(SocketOrChannelConnectionImpl.java:354)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.handleEvent(SocketOrChannelConnectionImpl.java:1098)
            at com.sun.corba.se.impl.transport.SelectorImpl.run(SelectorImpl.java:282)
    Caused by: org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 211  completed: No
            at com.sun.corba.se.impl.logging.ORBUtilSystemException.ioexceptionWhenReadingConnection(ORBUtilSystemException.java:2456)
            at com.sun.corba.se.impl.logging.ORBUtilSystemException.ioexceptionWhenReadingConnection(ORBUtilSystemException.java:2474)
            at com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase.readGIOPHeader(MessageBase.java:116)
            at com.sun.corba.se.impl.transport.CorbaContactInfoBase.createMessageMediator(CorbaContactInfoBase.java:150)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.readBits(SocketOrChannelConnectionImpl.java:314)
            ... 2 more
    Caused by: java.io.IOException: End-of-stream
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.readFully(SocketOrChannelConnectionImpl.java:602)
            at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.read(SocketOrChannelConnectionImpl.java:521)
            at com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase.readGIOPHeader(MessageBase.java:112)
            ... 4 moreThe weird thing is that this only occurs when client applications are connected to the framework, but not for service instances.
    I've found this item in the bug database: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6426592
    It shows almost the same stacktrace, except for the cause of the IOException, and this was in Vista.
    We're running our parlay framework gateway on Solaris 10 1/06 s10x_u1wos_19a X86.
    Does anyone have any experience with this?

    hi EJP,
    I almost find that why i am getting error infact my client is behind natted network, when i access the IOR i got the non-natted host IP. So what you suggest how i compell server to give me IOR with natted IP
    Below is my error
    IOR:000000000000002749444c3a6f72672f63736170692f63732f49704368617267696e674d616e616765723a312e30000
    000000001000000000000008c000102000000000b31302e31312e31322e3100002ee000000000002c00564201000000122f69636d695f736573
    73696f6e5f706f6100202000000004000000000000022b72cdb01b000000035649530300000005000507017f000000000000000000000800000
    000564953000000000100000018000000000001000100000001050100010001010900000000
    Nov 1, 2007 1:01:44 PM com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
    WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 10.11.12.1; port:
    12000"
    org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)
    at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(Unknown Source)
    at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(Unknown Source)
    at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(Unknown Source)
    at org.omg.CORBA.portable.ObjectImpl._request(Unknown Source)
    at org.csapi.cs._IpChargingManagerStub.createChargingSession(_IpChargingManagerStub.java:18)
    at my.com.ngc.genico.ParlayUtil.main(ParlayUtil.java:131)
    Caused by: java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
    at java.nio.channels.SocketChannel.open(Unknown Source)
    at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(Unknown Source)
    ... 8 more
    org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)
    at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(Unknown Source)
    at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(Unknown Source)
    at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(Unknown Source)
    at org.omg.CORBA.portable.ObjectImpl._request(Unknown Source)
    at org.csapi.cs._IpChargingManagerStub.createChargingSession(_IpChargingManagerStub.java:18)
    at my.com.ngc.genico.ParlayUtil.main(ParlayUtil.java:131)
    Caused by: java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
    at java.nio.channels.SocketChannel.open(Unknown Source)
    at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(Unknown Source)
    ... 8 more
    Regards

  • Multi-threaded performance server using 2 ports to two-way communication

    Hi, I'm new in the forums so welcome everyone. I'm developing now an online computer game based on orginal Polish board-game, but it doesn't mean. Important is that I need to develope a high-performance multi-threaded server, which can serve... let's say few hundres of games, and a thousend of players simulateously. My server works on two ports/sockets.
    First one is represented by "ServerSocketChannel clientConSsc" in my code. The main thread in my server class which invokes the method "run()" (which You can see below), registers clientConSsc with Selector and then repeatingly accepts incoming connections from clients on this socket. When connection(channel) is estabilished and clients wants to write some request to this channel, the main thread on server creates a new instance of class "RequestHandler" which extends Thread and handles this request (reads the request from channel, makes some changes on server, spreads some new messages to other clients in the same game and so on... everything on the same socket/port/channel). Then the channel/connection is closed by the server - I call such connections: "a short connections". In the same time the main thread continues the loop and is still able to accept connections from another players. That's the idea of multi-threaded server, right? :) And to this point, everything works fine, but... what if the server wants to trigger some new command, write new information to client?
    Server could have tried to open a SocketChannel to client's IP address, but then the client programme would have to create and ServerSocketChannel object, bind it to some InetAddress and then... and then client becomes a server! - that breaks the idea of client-server cooperation and demands on players of my game to have routed some port on their machines. To resolve this problem I made some sort of "system" which, when some player/client is logging into my server, accepts second (this time constant, not "short") connection on the second port I mentoined on the beginning. This connection is held in variable "SocketChannel serverCon" of class "Player" - which reflects a player logged onto server. Server maintains every such connection till the client logs off. After the connection is accepted, the player whom connection it was is added to collection called "playersToRegisterToWrite". After the Selector.selectNow() is invoked (as You can see in the code below), each and every player's connection is registered in selector (with selection key - OP_WRITE and attachment pointing on owning player). In the same time client's code is trying to read some bytes from this connection and blocks on it until some bytes are written to this connection. When server wants to "tell" something to client, deliver some message/command, it creates a new instance of class which extends an abstract class called "ServerAction" (another new thread) and adds it to collection "actionsToDo". In ServerAction's method "run()" there are whole code to interact with client (e.g. send an update of players' list, an update of games' list, a chat message). Finnaly when Selector informs the server that some connection is writable (some client is waiting for commands), then server checks if there's any "actionToDo" involving this client/player. If there is, it unregisters the connection from Selector (so no other ServerAction (thread) can write on this connection) and starts the action. At the end of every "run()" method of subclass of ServerAction there's a code, which again adds the player to collection "playersToRegisterToWrite", so the player's connection can again be registered in Selector and the player can again receive informations from server - after it consumed THIS "ServerAction".
    It looks to me like it should be working fine, but it's not. When I test my server and clients on the same machine (no ping/latency) everything seems to be working fine. But when it comes to play my game with somebody even on LAN or through the Internet there comes the problems. My first socket I describe (and first type of connections - short connections) works perfectly fine, so the requests triggered by client are delivered and handled properly. But the second socket is cirppling. For example: the server triggers a command refering to an update of clients logged to server' list. It is triggered by Selector so the client should be ready to read data from server, so the server sends data! And the client never receives it... Why?
    It experimented a whole lot of time on SocketChannel's method "configureBlocking(boolean)", but it never helps. I think the client should always block it's listening thread on connection, contratry to server which is ment to be fast, so it should send the data through non-blocking channels. Am I right? Are there any rules refering blocking configuration of SocketChannels?
    I will be grateful for every answer. To help You out I attach also drafts from run()'s methods of my classes.
    Server's main method - main thread :
        public void run() {
           try {
                selector = Selector.open();
                clientConSsc.configureBlocking(false);
                clientConSsc.register(selector , SelectionKey.OP_ACCEPT);
                while(serverRunning) {
                    try {
                        selector.selectNow();
                        Iterator it;
                        synchronized(playersToRegisterToWrite) {
                            it = playersToRegisterToWrite.iterator();
                            while(it.hasNext()) {
                                Player player = (Player)it.next();
                                it.remove();
                                player.serverCon.configureBlocking(false);
                                player.serverCon.register(selector , SelectionKey.OP_WRITE , player);
                        Set keys = selector.selectedKeys() {
                        it = keys.iterator();
                        while(it.hasNext()) {
                            SelectionKey key = (SelectionKey)it.next();
                            if(key.isAcceptable()) {
                                it.remove();
                                clientCon = clientConSsc.accept();
                                clientCon.configureBlocking(false);
                                clientCon.register(selector , SelectionKey.OP_READ);
                                continue;
                            if(key.isReadable()) {
                                it.remove();
                                key.cancel();
                                new RequestHandler(this , (SocketChannel)key.channel()).start();
                                continue;
                            if(key.isWritable()) {
                                if(key.attachment() != null ) {
                                    ServerAction action = null;
                                    synchronized(actionsToDo) {
                                        Iterator aIt = actionsToDo.iterator();
                                        while(aIt.hasNext()) {
                                            ServerAction temp = (ServerAction)aIt.next();
                                            if(temp.getPlayer().equals((Player)key.attachment())) {
                                                action = temp;
                                                aIt.remove();
                                                break;
                                    if(action != null) {
                                        key.channel().configureBlocking(false);
                                        it.remove();
                                        key.cancel();
                                        action.start();
                                continue;
                    } catch(Exception e) {
                        statusArea.append(e.toString() + "\n");
                        e.printStackTrace();
                        continue;
            } catch(ClosedChannelException e) {
                statusArea.append(e.toString() + "\n");
            } catch(IOException e) {
                statusArea.append(e.toString() + "\n");
                A part of server's RequestHandler's class' method run() - the method which handles requests triggered by client on first port:
    public void run() {
            boolean served = false;
                try {
                    channel.configureBlocking(true);
                    retryCount++;
                    retry = false;
                    String command = ns.readText(channel).trim();
                    ns.statusArea.append("ktos przesyla komende: " + command + "\n");
                    if(command != null && !command.equals("ERROR")) {
                        String[] cmd = command.split("�");
                        ns.statusArea.append("komenda: " + cmd[0] + "\n");
                        if(cmd[0].equals("CHAT")) {
                            if(cmd.length != 5) {
                                retry();
                            } else {
                                if(cmd[2].equals("NOGAME")) {      // jezeli nie ma okreslonej gry czyli rozsylamy do wszystkich
                                    for(int i = 0 ; i < ns.loggedPlayersListItems.size() ; i++) {
                                        Player current = (Player)ns.loggedPlayersListItems.get(i);
                                        if(current.state == Player.CHOOSING && !current.equals(new Player(Integer.parseInt(cmd[1]))))   // jezeli gracz jest w okienku wybierania gry to wysylamy mu broadcast
                                            ns.actionsToDo.add(new SendMsg(ns , current , "CHAT�" + cmd[1] + "�" + cmd[3] + "�" + cmd[4]));
                                } else {
                                    Game game = (Game)ns.gamesListItems.get(ns.gamesListItems.indexOf(new Game(Integer.parseInt(cmd[2]))));
                                    for(int i = 0 ; i < game.players.size() ; i++) {
                                        Player current = (Player)game.players.get(i);
                                        if(!current.equals(new Player(Integer.parseInt(cmd[1]))))
                                            ns.actionsToDo.add(new SendMsg(ns , current , "CHAT�" + cmd[1] + "�" + cmd[3] + "�" + cmd[4]));
                                served = true;
                        } else if(cmd[0].equals("GETGAMEINFO")) {
                            if(cmd.length != 3)
                                retry();
                            else {
                                int gameID = Integer.parseInt(cmd[2]);
                                ns.statusArea.append("poproszono o informacje o grze nr: " + gameID + "\n");
                                Game checkedGame = new Game(gameID);
                                if(ns.gamesListItems.contains(checkedGame)) {
                                    Game game = (Game)ns.gamesListItems.get(ns.gamesListItems.indexOf(checkedGame));
                                    channel.configureBlocking(true);
                                    ObjectOutputStream oos = new ObjectOutputStream(channel.socket().getOutputStream());
                                    oos.writeObject(game);
                                    oos.writeObject(game.players);
                                    oos.flush();
                                    ns.statusArea.append("wyslano informacje o grze nr: " + gameID + "\n");
                                } else {
                                    ns.statusArea.append("brak gry o nr: " + gameID + "\n");
                                served = true;
                } catch(IOException e) {
                    e.printStackTrace();
            if(!served) {
                ns.findAndDisconnectPlayer(channel);
            try {
                channel.close();
            } catch(IOException e) {
                e.printStackTrace();
        }An example of ServerAction's subclass - the class which triggers server commands to client on second port:
    class UpdateLoggedPlayersList extends ServerAction {
        public UpdateLoggedPlayersList(NeuroServer ns , Player player) {
            super(ns , player);
        public void run() {
            try {
                serverCon.configureBlocking(true);
                ns.sendText("UPDATELOGGEDPLAYERSLIST" , serverCon);
                if(ns.readText(serverCon).equals("OK")) {
                    ObjectOutputStream oos = new ObjectOutputStream(serverCon.socket().getOutputStream());
                    oos.writeObject(ns.loggedPlayersListItems);
                    oos.flush();
                synchronized(ns.playersToRegisterToWrite) {
                     ns.playersToRegisterToWrite.add(player);
            } catch(IOException e) {
                e.printStackTrace();
    }A part of client's CmdHandler's class' method run() - the method which handles commands triggered by server:
    public void run() {
        try {
            while(works) {
                String command = nc.readText(nc.serverCon);
                System.out.println("Server przesyla komende: " + command + "\n");
                String[] cmd = command.split("�");
                if(cmd[0] != null && !cmd[0].equals("ERROR")) {
                    if(cmd[0].equals("CHAT")) {
                        if(nc.chooseGameDialog != null && nc.chooseGameDialog.isVisible()) {     // jezeli na wybieraniu gry
                            newChatEntry(cmd[2] , null , cmd[3] , nc.chooseGameDialog.chatPane);
                        } else if(nc.readyDialog != null && nc.readyDialog.isVisible()) {  // jesli na przygotowywaniu
                            Player sender = (Player)nc.actGame.players.get(nc.actGame.players.indexOf(new Player(Integer.parseInt(cmd[1]))));
                            newChatEntry(cmd[2] , sender.fraction , cmd[3] , nc.readyDialog.chatPane);
                        } else if(nc.ng != null) {                   // jesli w grze
                            Player sender = (Player)nc.actGame.players.get(nc.actGame.players.indexOf(new Player(Integer.parseInt(cmd[1]))));
                            newChatEntry(cmd[2] , sender.fraction , cmd[3] , nc.ng.inGameChatPane);
                    } else if(cmd[0].equals("UPDATELOGGEDPLAYERSLIST")) {
                        nc.sendText("OK" , nc.serverCon , false);
                        nc.serverCon.configureBlocking(true);
                        ObjectInputStream ois = new ObjectInputStream(nc.serverCon.socket().getInputStream());
                        DefaultListModel players = (DefaultListModel)ois.readObject();
                        nc.chooseGameDialog.updateLoggedPlayersList(players);
        } catch(IndexOutOfBoundsException e) {
            System.out.println(e);
        } catch(IOException e) {
            System.out.println(e);
        } catch(ClassNotFoundException e) {
            System.out.println(e);
    }And two methods I used in codes above: sendText(String text , SocketChannel sc) and readText(SocketChannel sc) - they are my "utility" methods, which I use to send and receive Strings through specified SocketChannels.
    boolean sendText(String text , SocketChannel sc) {
        ByteBuffer bbuf = ByteBuffer.allocate(BSIZE);
        boolean sendRetry;
        boolean sent = false;
        do {
            sendRetry = false;
            try {
                StringBuffer cmd = new StringBuffer();
                cmd.setLength(0);
                if(text.length()+4 < 100)
                    cmd.append("0");
                if(text.length()+4 < 10)
                    cmd.append("0");
                cmd.append(Integer.toString(text.length()+4) + "�");
                cmd.append(text);
                cmd.append("\n");
                bbuf = charset.encode(CharBuffer.wrap(cmd));
                sc.write(bbuf);
                bbuf.clear();
                int n = sc.read(bbuf);
                if(n == 1) {
                    bbuf.flip();
                    Byte re = bbuf.get();
                    if(re == 1) {
                        sendRetry = true;
                    } else {
                        sent = true;
            } catch(Exception e) {
                findAndDisconnectPlayer(sc);
                try {
                    sc.close();
                } catch(IOException f) {
                    f.printStackTrace();
                return false;
        } while(!sent && sendRetry);
        return true;
    String readText(SocketChannel sc) {
        ByteBuffer bbuf = ByteBuffer.allocate(BSIZE);
        int readRetryCount = -1;
        boolean readRetry;
        do {
            readRetry = false;
            readRetryCount++;
            StringBuffer cmd = new StringBuffer();
            cmd.setLength(0);
            bbuf.clear();
            try {
                readLoop:
                while(true) {
                    int n = sc.read(bbuf);
                    if(n > 0) {
                        bbuf.flip();
                        CharBuffer cbuf = charset.decode(bbuf);
                        while(cbuf.hasRemaining()) {
                            char c = cbuf.get();
                            if(c == '\r' || c == '\n') break readLoop;
                            cmd.append(c);
                    } else break;
                statusArea.append(Thread.currentThread().getId() + " readText() odczytuje: " + cmd.toString() + "\n");
                if(cmd.length() < 3 || Integer.parseInt(cmd.substring(0 , 3)) != cmd.length()) {
                    sc.write(ByteBuffer.wrap(new byte[] {1}));
                    readRetry = true;
                } else {
                    sc.write(ByteBuffer.wrap(new byte[] {0}));    // length OK
                    return cmd.toString().substring(4 , cmd.toString().length());
            } catch(Exception e) {
                findAndDisconnectPlayer(sc);
                try {
                    sc.close();
                } catch(IOException f) {
                    f.printStackTrace();
                return "ERROR";
        } while(readRetry && readRetryCount < 3);
        findAndDisconnectPlayer(sc);
        try {
            sc.close();
        } catch(IOException e) {
            e.printStackTrace();
        return "ERROR";
    }Edited by: Kakalec on Jul 23, 2008 11:04 AM

    You seem to be using a horrendous mixture of PrintWriters, BufferedReaders, ObjectOutputStreams, and no doubt ObjectInputStreams. You can't do that.
    Some rules about this:
    (a) Whenever you use a stream or reader or writer on a socket, you must allocate it once for the life of the socket, not every time you want to do an I/O.
    There are many reasons for this including losing buffered data in the old stream and auto-closure of the socket on garbage-collection of the old stream.
    (b) You can't mix stream types on the same socket. (i) If you're writing objects, use an ObjectOutputStream, you must read with an ObjectInputStream, and you can't read or write anything that isn't supported by the API of ObjectOutputStream. (ii) If you're writing lines, use a BufferedWriter and a BufferedReader at the other end. If you're writing characters, use a Writer and a Reader. (iii) If you're writing primitive data or UTF strings, use a DataOutputStream and a DataInputStream. (iv) If you're writing bytes, use DataOutputStream and a DataInputStream or an OutputStream and an InputStream. You can't mix (i), (ii), (iii), and (iv).
    (c) Don't use PrintWriter or PrintStream over the network. They swallow exceptions that you need to know about. They are for writing to the console, or log files, where you don't really care about exceptions.
    (d) Call flush() before reading.
    (e) Always close the 'outermost' output stream or writer of a socket, never the input stream or the socket itself. Closing any of these closes the socket and therefore makes the other stream unusable, but only closing the output stream/writer will flush it.

  • How can I speed up this VI? It only checks 6 channels, but updates only 20/sec

    I am measuring 6 channels of current in this VI. It will only update about 20 times per second.
    The VI is quite simple. It measures current on 6 channels, performs a running average using shift registers, and performs some math on the current to convert it to loads. It also writes all values to a file once per iteration. I ran a similar VI that only checked 4 channels and did not write to the file, but it is not much faster. I also tried to make sure all coercion dots were eliminated, but that did not help much either.
    Can anyone take a quick look and see if there is something obvious I am doing that is slowing it down? Or is this a reasonable update rate for this VI?
    The top-l
    evel VI is the one called "RunTestBed 24v loop loop.vi".
    Thanks!
    Mike
    Attachments:
    RunTestBed_24v_loop_loop.llb ‏349 KB

    You are using high lvel VI to do you I/O inside the loop.
    Take a look at the shipped example that demonstrates how to start a do a continuous acquisition.
    The example is title something like
    Continuous double buffered acquisition.
    The High VI's you are using are configuring the I/O and allocating buffers durring each iteration. THe eaxample I mentioned will do all of this one up front and then just re-use everything inside the loop.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Performance Tuning in CRM

    Hi All,
    Can any one help me to important OSS Notes in CRM performance tuning, CRMIC webclient performance, web client channel performance.
    Thanks & Regards,
    Sandeep

    Hi Sandeep,
    Please take a look at the following SAP NOTES for performance tuning in CRM 2007 Webclient:
    Note 1048388 - General Performance improvements of BSP transactions
    Note 1228076 - CRM Web UI: Frontend performance DDLB and input changes
    Note 1246144 - Advanced Search right side hidden when resolution: 1024X768
    Note 1242599 - IE7: Message # shines through the "More" dropbox
    Note 1240769 - Native DDLB value not set when its disabled
    Note 1237437 - Config Mode: FireFox support and Visual enhancements
    Note 1230443 - Scrollbar missing or not showing up on some CRM views
    Best Regards,
    Gabriel

  • IP address lookup and Sockets

    Hi All,
    I have created a Socket using java.net.Socket(String host, int port) by passing the required host, port parameters.
    The host string is specified in the form of xxx.xxx.xxx.xxx, even though the Java
    program(client) is running on the same machine where the server socket is listening, (IP address is not specified as 'loopback address' localhost/127.0.0.1).
    Below are my queries for the above mentioned scenario.
    1) When the data is sent/received to/from the Socket, will the data
    travel across the network and return back to the same machine or it will be a direct send/receive within the same machine?
    2) Is the loopback address 'localhost/127.0.0.1' used internally by the underlying socket implementation without performing lookup of the IP address in the network?
    3) Does this behavior varies/depends on the underlying OS or the network
    protocol/configuration?
    Thanks in advance,
    Sreenivasulu

    1: it depends upon the mechanism through which the sockets between client and server are established (in ur case the client and the server is the same machine). When u specify the localhost/127.0.0.1, port where the server is listening, then i think the request should go out to the network and the OS will handle it by it self and manage the connection then the data will not travel through the whole network. Other wise when u specify that the server is listening on 192.168.0.0:9000 then the OS will go to look up server /dns it will tell him where this system in laying on the network is it in he same netwrok or out side this network and then a connection is established now the data will travel through the network, cause it will look for the system 192.168.0.0.
    2: when u will use the loopback for specific IP then the direct connection is made to the system.
    3: i can say nothing about this issus how the other OS are behaving cause i had mostly worked on Windows NT/2000
    i am in the learning process. If i am wrong plz correct me. And i am also very much interested for the replies from other users...
    thanx

  • Performance of stock 1.83 with 512MB

    Hello,
    Just wanted to know what performance will I be looking at with the stock MacBook Pro 1.83 model. Where I'm coming from is a PowerBook Ti 400 1GB. I know this is like night from day but any info would help. I will add ram later but right now just the stock model with 512MB is what I will be using for some time.
    Thanks for any info.
    Aurora Logan
      Mac OS X (10.4.5)  

    I have a MBP 1.83 with standard 512 MB. I do alot of video and burning DVD's and want to upgrade the RAM as much as possible for my MBP 1.83 configuration.
    Let me see if I am understanding this statement from Kappy and others correctly: "You need two modules with the same specifications, but they do not need to be a matched pair."
    So, are you saying that I do not have to buy another 512MB (is this a matched pair?) and I am free to put 1 or 2 Gig of memory in this second slot, and I can still benefit from "dual channel performance'? And what specs am I looking for?... the same manufacter? or...?
    Specific recommendations about brands from online places like OWC or stores like Fry's?
    Thanks!
    Nancy
    Mac Book Pro 1.83 & 733 PowerMac   Mac OS X (10.4.5)  

  • ORB does not perform clean up after destroy() is called.

    hi,
    the HelloClient example (POA model) which is provided in the Java IDL tutorials, does not perform clean up after the execution is complete.
    i.e. i can still find the Socket descriptors in the file system under the path (/proc/p_id/fd). Do we need to explicitly destroy the sockets inorder to perform the required clean up??the OS i'm using is Linux.
    if yes, then how do i do that.... the following are the steps to reproduce the problem:
    1)start HelloServer
    2)start HelloClient
    3)check file count in /proc/process_id/fd before calling init.
    4)invoke ORB.destroy() method.
    5)check file count in /proc/process-id/fd after destroy completes.I have included Thread.sleep(25000) inorder to check the file count dynamically at each stage of execution.
    Any help in this regard is welcome....!!
    thanks in advance

    Hello:
    This reply may be long after the time that you need it ... but the problem
    that you are experiencing sounds very much like a bug that was fixed in the J2SE 1.5.0_10 release.
    It is bug 6354718 ....
    In the evaluation section of that bug they note:
    Yes. It's a known bug in ORB connection management. What's happening here is, the connectionCache that maintains both inbound and outbound connections does not reclaim connections, upon ORB destroy() call. There is a connection reclaim() logic in place, but does not kick in, until it reaches certain watermark levels. Since, a single client can have a multiple ORBs and thereby multiple outbound connections (in the reported case) , with each cache having exactly one connection which leaks up on ORB exit. This leak multiplies based on the number of ORBs and time period over which client stays live, up and running.
    The solution is, to walk through the connection cache and close each connection,
    no matter what the watermark levels are. This can be done at the corba transport manager close() call.
    Note: In the above evaluation they tell you how to fix it yourself but I believe (I haven't tested it yet ....) that if you upgrade to JDK 1.5.0_10, you should find that it has been fixed for you.
    I hope that I'm not steering you wrong, but that's my take on your situation.
    John

  • WL6.0 server start - socket error

    Hi,
    I was trying to start my example and petstore server, I got the following
    message while starting it, and it shut down after if found that something
    might be using the socket. Can anyone help me with this? Thanks.
    <Jan 18, 2001 1:19:38 AM PST> <Notice> <Management> <Loading configuration
    file .\config\examples\config.xml ...
    >
    <Jan 18, 2001 1:19:42 AM PST> <Info> <Logging> <Only log messages of
    severity "Error" or worse will be displayed
    in this window. This can be changed at Admin Console> examples> Servers>
    examplesServer> Logging> Debugging> St
    dout severity threshold>
    <Jan 18, 2001 1:20:15 AM PST> <Notice> <WebLogicServer> <WebLogic Server
    started>
    <Jan 18, 2001 1:20:15 AM PST> <Emergency> <WebLogicServer> <Unable to create
    a server socket for port: 7002. jav
    a.net.BindException: Address in use: JVM_Bind Perhaps another process is
    using port 7002.>
    <Jan 18, 2001 1:20:15 AM PST> <Emergency> <WebLogicServer> <Unable to create
    a server socket for port: 7001. jav
    a.net.BindException: Address in use: JVM_Bind Perhaps another process is
    using port 7001.>
    <Jan 18, 2001 1:20:15 AM PST> <Emergency> <WebLogicServer> <The WebLogic
    Server is no longer listening for conne
    ctions. You should probably restart it.>
    <Jan 18, 2001 1:20:15 AM PST> <Emergency> <WebLogicServer> <The WebLogic
    Server is no longer listening for conne
    ctions. You should probably restart it.>

    On Tue, 30 Aug 2005 13:01:37 -0700, Merline Sigamani <> wrote:
    Could someone tell me why I would be getting this error?
    How can I figure out which port is being used and which are free? I checked the /etc/services I didn't see 8001 listed there, so why this conflict?
    Please help. Any suggestion would be appericiated.
    thanks
    merline
    ####<Aug 30, 2005 12:53:19 PM CDT> <Emergency> <WebLogicServer> <sunserv3> <STAp
    p1> <ListenThread.Default> <<WLS Kernel>> <> <BEA-000350> <Unable to create a se
    rver socket on Channel Default for: 10.200.110.51, port: 8001. java.net.BindExce
    ption: Cannot assign requested address Perhaps the address 10.200.110.51 is inco
    rrect or another process is using port 8001.>
    ####<Aug 30, 2005 12:53:20 PM CDT> <Emergency> <Security> <sunserv3> <STApp1> <m
    ain> <<WLS Kernel>> <> <BEA-090085> <Server failed to bind to the configured por
    t. The port may already be used by another process.>
    ####<Aug 30, 2005 12:53:20 PM CDT> <Emergency> <WebLogicServer> <sunserv3> <STAp
    p1> <main> <<WLS Kernel>> <> <BEA-000342> <Unable to initialize the server: Serv
    er failed to bind to the requested port. See preceeding log message for details.
    >well you can can download a tool if you are on windows (I use one called tcp
    view) or maybe zone alrm would tell you what ports are being used already.
    You can see what processes are using what ports then easily. I am not sure
    what to use on other os's.
    Also, you might not care, just set your system to use say port 8002 instead of
    8001 and see if that works / is open.
    Good Luck,
    Jeff

  • 100% CPU Utilisation while reading from socket

    I have writted a ServerSocket program to read data from ethernet client bridge. client-bridge is a system which converts serial data to TCP packet and vice versa. I can read from the client bridge only through creating a server socket and waiting for the client bridge to make a client socket connection (ServerSocket.accept() method.
    The problem that I m facing is that, the client bridge is creating connection only once. I have created an infinite loop which keeps on reading from the socket. The performance of the application goes down drastically (100% CPU utilisation through task manager) when this application is run. Is there a better way of reading data from the client bridge. The client bridge is not in our control and the server can only wait for the client to make connection.
    Please help. Thanking you all in anticipation.
    Regards,
    Amitabha

    If I close the client socket will the client create a new socket to
    transmit data or it depends on the client application.
    I have also tried creating a new socket connection for
    reading each frame of the protocol. but the client
    creates only one socket. What might be the problem?I bet it depends on the client app because your server app only waits for a connection from the client. So it's the client that initiates the connection. When you disconnect the client socket then you will have to wait for another client request. what you can do is to stay connected (unless of course client disconnects itself) and just keep on reading from the client socket.

  • Does the SONY VAIO F Series SVF15412CXB support dual channel memory?

    Does the SONY VAIO F Series SVF15412CXB support dual channel memory?  Or does it only have one slot?
    I'm curious if I can put a second stick of RAM in there for dual channel performance.

    Hi Mark, Thanks for the response.  Can you please double check that for me, or post a link to the documentation where you saw that?  I asked this question on Newegg, too, and one of the respondants heard differently:
    "i found out from sony that there is only 1 slot cause i was gonna get 1 more 4GB stick of ram for 8Gb. So iwas upset about that cause i have to get 8GB now and it costs 100$ for an 8Gb stick of ram on ebay. So this ram is expensive. So im sticking with 4Gb for now. This is a very good laptop though. I use it primarily for minecarft and steam and i get around 100 fps on minecraft so its good. I hope this helps." It's just confusing because other laptop advertisments I've seen openly stated how many RAM slots the computer had and how many were used upon purchase.  I haven't found anything like that which makes me think that there's only one slot for RAM. Thanks,Gremark

  • Rt.jar differences in jdk1.5

    Hello all,
    I have used JDK1.4's sun.net.ProgressData and sun.net.ProgressEntry classes. Suddenly these classes have been removed from /lib/rt.jar. What API should I use instead?
    Thanks,
    Guru

    AniKar-JavaWorld wrote:
    I have wrote my own Datagram channel which functions the same way as the original one except it will create and wrap a raw socket. To make use of the other
    sun packages we need to have it class inside the rt.jarYou don't need to place your class in rt.jar. Just place the class on the bootclasspath.

Maybe you are looking for