Skip to content

Commit 441a66b

Browse files
authored
Issue 342 | TCP/UD Socket based Table Streamer (#345)
* - Implements TCP socket streamer. Opens on port 31416. - Added a test case which also shows how to use it. - The output is in JSON format. * it is a good idea to zip the data with time for server. * Temp commit. Needs to make sure that recv socket can read the data. * Ready for a PR. * Added moose server. * This is nice but I don't know what is going on behind the scene. Must implement from the scratch. * Using raw sockets from python. * I can now execute script on server. * Updated a bit more. * This works with ghevar [skip ci] * A working version [skip ci] * Extra code which saves all images to pdf file. * A working version [skip ci] Better path handling and result streaming. Needs to have a protocol for sending messages. python -m moose.server run the server. removed pyflakes reported error [skip ci] remove default -h (help) which was in conflict with -h (--host). [skip ci] * Pipeline is complete. Works fine. * Fixed pylint error. * Socket works on OSX as well. * Added logger. Need to test from different network. * block socket till specified data is received. Removed old dreprecated scripts. They are part of parent moose repo and no longer required here. Some more corner cases are handled. Don't use fullpath. Autosetup SocketStreamer when environment variable MOOSE_TCP_STREAMER_ADDRESS is set to e.g. localhost:31416 . Try till all data is recieved. * Squashed commit of the following: commit 206baccabb1d7c7b5b90accf9961376febcaab47 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Tue Feb 5 10:11:27 2019 +0530 removed the background client. Accept only 1 client. commit b71dbb3d3f312ca1eec4fb456e8ea758123ad505 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Mon Feb 4 15:55:44 2019 +0530 changed the implementation. Now process function does nothing. We launch a thread in the background which monitor connections and stream the data. If no environment variable is set then no data is streamed and tables are safe. Tables are flushed when data is streamed. Need to change this behaviour. * Socket streamer are alos available. * added unix domain socket as well. * Renamed some tests. * On OSX, I can't send all the data [skip ci]. * Needs some more work [skip ci]. * Squashed commit of the following: commit ff2b989659fdeb34ff5095177e17325286bd6746 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 21:26:03 2019 +0530 Test passes on linux. commit 8ca89dc Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 19:27:05 2019 +0530 Latency in TCP socket is bad. commit c3e15d8 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 18:56:36 2019 +0530 Fixed both tests. Now test on OSX. commit c731328 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 18:52:08 2019 +0530 Time is handled by table. commit 701ea55 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 16:26:35 2019 +0530 Fixed frame size helped. commit b168681 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 15:59:38 2019 +0530 Test on osx [skip ci]. * Squashed commit of the following: commit c3e15d8 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 18:56:36 2019 +0530 Fixed both tests. Now test on OSX. commit c731328 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 18:52:08 2019 +0530 Time is handled by table. commit 701ea55 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 16:26:35 2019 +0530 Fixed frame size helped. commit b168681 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Wed Feb 6 15:59:38 2019 +0530 Test on osx [skip ci]. * TCP socket latency is high for small simulations. * TCP socket works with latency but OK to use. * Environment variable is working file. Time to merge.
1 parent c67f8c0 commit 441a66b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4306
-2989
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ else()
9797
message(STATUS "Building for Release/No unit tests.")
9898
set(CMAKE_BUILD_TYPE Release)
9999
add_definitions(-UDO_UNIT_TESTS -O3 -DDISABLE_DEBUG)
100-
100+
101101
# DO NOT Treat all warnings as errors. With some compilers and newer versions
102102
# this often causes headache.
103103
# add_definitions(-Werror)
@@ -353,7 +353,7 @@ if(SYSTEM_SHARED_LIBS)
353353
list(REMOVE_DUPLICATES SYSTEM_SHARED_LIBS)
354354
endif( )
355355

356-
# cmake --help-policy CMP0042. Also in pymoose/CMakeLists.txt
356+
# cmake --help-policy CMP0042. Also in pymoose/CMakeLists.txt
357357
# More details:
358358
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
359359
# especially section 'Mac OS X and the RPATH'
@@ -528,8 +528,8 @@ foreach( _py_script ${PY_SCRIPTS} )
528528
file( READ ${_py_script} pytext)
529529
string(MD5 _md5 "${pytext}")
530530
set(TGT_NAME "${_py_name}-${_md5}" )
531-
set(PYLINT_OPTIONS --disable=no-member --disable=no-name-in-module
532-
--disable=invalid-unary-operand-type
531+
set(PYLINT_OPTIONS --disable=no-member --disable=no-name-in-module
532+
--disable=invalid-unary-operand-type
533533
--disable=import-error
534534
--disable=no-method-argument
535535
)

basecode/ObjId.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,111 +17,111 @@
1717
// Doesn't know how to deal with off-node bad fields.
1818
bool ObjId::bad() const
1919
{
20-
Element* elm = id.element();
21-
return ( elm == 0 ||
22-
dataIndex == BADINDEX ||
23-
fieldIndex == BADINDEX ||
24-
dataIndex >= elm->numData()
25-
/*
26-
* We have a bit of a problem here. The FieldElement can exist
27-
* with zero fields, and is invalid for field lookups but valid
28-
* for the element level lookups. I should rather not create the
29-
* FieldElements this way.
30-
|| (
31-
elm->getNode( dataIndex ) == Shell::myNode() &&
32-
fieldIndex >= elm->numField( dataIndex - elm->localDataStart() )
33-
)
34-
*/
35-
);
20+
Element* elm = id.element();
21+
return ( elm == 0 ||
22+
dataIndex == BADINDEX ||
23+
fieldIndex == BADINDEX ||
24+
dataIndex >= elm->numData()
25+
/*
26+
* We have a bit of a problem here. The FieldElement can exist
27+
* with zero fields, and is invalid for field lookups but valid
28+
* for the element level lookups. I should rather not create the
29+
* FieldElements this way.
30+
|| (
31+
elm->getNode( dataIndex ) == Shell::myNode() &&
32+
fieldIndex >= elm->numField( dataIndex - elm->localDataStart() )
33+
)
34+
*/
35+
);
3636
}
3737

3838
ostream& operator <<( ostream& s, const ObjId& i )
3939
{
40-
if ( i.dataIndex == 0 && i.fieldIndex == 0 )
41-
s << i.id;
42-
else if ( i.fieldIndex == 0 )
43-
s << i.id << "[" << i.dataIndex << "]";
44-
else
45-
s << i.id << "[" << i.dataIndex << "][" << i.fieldIndex << "]";
46-
return s;
40+
if ( i.dataIndex == 0 && i.fieldIndex == 0 )
41+
s << i.id;
42+
else if ( i.fieldIndex == 0 )
43+
s << i.id << "[" << i.dataIndex << "]";
44+
else
45+
s << i.id << "[" << i.dataIndex << "][" << i.fieldIndex << "]";
46+
return s;
4747
}
4848

4949
/**
5050
* need to complete implementation
5151
*/
5252
istream& operator >>( istream& s, ObjId& i )
5353
{
54-
s >> i.id;
55-
return s;
54+
s >> i.id;
55+
return s;
5656
}
5757

5858
//////////////////////////////////////////////////////////////
5959
ObjId::ObjId( const string& path )
6060
{
61-
Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
62-
assert( shell );
63-
*this = shell->doFind( path );
61+
Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
62+
assert( shell );
63+
*this = shell->doFind( path );
6464
}
6565

6666
Eref ObjId::eref() const
6767
{
68-
return Eref( id.element(), dataIndex, fieldIndex );
68+
return Eref( id.element(), dataIndex, fieldIndex );
6969
}
7070

7171
bool ObjId::operator==( const ObjId& other ) const
7272
{
73-
return ( id == other.id && dataIndex == other.dataIndex &&
74-
fieldIndex == other.fieldIndex );
73+
return ( id == other.id && dataIndex == other.dataIndex &&
74+
fieldIndex == other.fieldIndex );
7575
}
7676

7777
bool ObjId::operator!=( const ObjId& other ) const
7878
{
79-
return ( id != other.id || dataIndex != other.dataIndex ||
80-
fieldIndex != other.fieldIndex );
79+
return ( id != other.id || dataIndex != other.dataIndex ||
80+
fieldIndex != other.fieldIndex );
8181
}
8282

8383
bool ObjId::operator<( const ObjId& other ) const
8484
{
85-
return ( id < other.id ||
86-
(id == other.id && (
87-
dataIndex < other.dataIndex ||
88-
( dataIndex == other.dataIndex &&
89-
fieldIndex < other.fieldIndex )
90-
)
91-
)
92-
);
85+
return ( id < other.id ||
86+
(id == other.id && (
87+
dataIndex < other.dataIndex ||
88+
( dataIndex == other.dataIndex &&
89+
fieldIndex < other.fieldIndex )
90+
)
91+
)
92+
);
9393
}
9494

9595
bool ObjId::isDataHere() const
9696
{
97-
return ( id.element()->getNode( dataIndex ) == Shell::myNode() );
97+
return ( id.element()->getNode( dataIndex ) == Shell::myNode() );
9898
}
9999

100100
bool ObjId::isGlobal() const
101101
{
102-
return ( id.element()->isGlobal() );
102+
return ( id.element()->isGlobal() );
103103
}
104104

105105
bool ObjId::isOffNode() const
106106
{
107-
return ( Shell::numNodes() > 1 &&
108-
( id.element()->isGlobal() ||
109-
id.element()->getNode( dataIndex ) != Shell::myNode() )
110-
);
107+
return ( Shell::numNodes() > 1 &&
108+
( id.element()->isGlobal() ||
109+
id.element()->getNode( dataIndex ) != Shell::myNode() )
110+
);
111111
}
112112

113113
char* ObjId::data() const
114114
{
115-
return id.element()->data( id.element()->rawIndex( dataIndex ),
116-
fieldIndex );
115+
return id.element()->data( id.element()->rawIndex( dataIndex ),
116+
fieldIndex );
117117
}
118118

119119
string ObjId::path() const
120120
{
121-
return Neutral::path( eref() );
121+
return Neutral::path( eref() );
122122
}
123123

124124
Element* ObjId::element() const
125125
{
126-
return id.element();
126+
return id.element();
127127
}

basecode/ObjId.h

Lines changed: 96 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -19,95 +19,102 @@
1919
*/
2020
class ObjId
2121
{
22-
friend ostream& operator <<( ostream& s, const ObjId& i );
23-
friend istream& operator >>( istream& s, ObjId& i );
24-
public:
25-
//////////////////////////////////////////////////////////////
26-
// ObjId creation
27-
//////////////////////////////////////////////////////////////
28-
/**
29-
* Returns the root Id
30-
*/
31-
ObjId()
32-
: id(), dataIndex( 0 ), fieldIndex( 0 )
33-
{;}
34-
35-
/**
36-
* Creates a ObjId using specified Id and DataIndex
37-
*/
38-
ObjId( Id i, unsigned int d, unsigned int f = 0 )
39-
: id( i ), dataIndex( d ), fieldIndex( f )
40-
{;}
41-
42-
ObjId( Id i )
43-
: id( i ), dataIndex( 0 ), fieldIndex( 0 )
44-
{;}
45-
46-
/**
47-
* Creates an ObjId by reading the path string
48-
* Returns bad on failure.
49-
*/
50-
ObjId( const string& path );
51-
52-
/**
53-
* Returns the absolute path including all array indices.
54-
*/
55-
string path() const;
56-
57-
/**
58-
* Returns the Eref matching itself.
59-
*/
60-
Eref eref() const;
61-
62-
/**
63-
* For equality check
64-
*/
65-
bool operator==( const ObjId& other ) const;
66-
bool operator!=( const ObjId& other ) const;
67-
68-
/**
69-
* For sorting
70-
*/
71-
bool operator<( const ObjId& other ) const;
72-
73-
/**
74-
* True if the data is present on the current node. Always true for
75-
* globals, which confuses the matter somewhat.
76-
*/
77-
bool isDataHere() const;
78-
79-
/// Returns true if the Element is global.
80-
bool isGlobal() const;
81-
82-
/// Returns true if we need to go off-node for calling operations
83-
bool isOffNode() const;
84-
85-
/**
86-
* Returns data entry for this object
87-
*/
88-
char* data() const;
89-
90-
/**
91-
* Returns Element part
92-
*/
93-
Element* element() const;
94-
95-
/**
96-
* Here are the data values.
97-
*/
98-
Id id;
99-
unsigned int dataIndex;
100-
unsigned int fieldIndex;
101-
102-
/**
103-
* True if the return value is bad: either returning a failure,
104-
* or the DataIndex or FieldIndex is out of range. However, this
105-
* is a node-local funtion so it can't report the FieldIndex status
106-
* in all cases.
107-
*/
108-
bool bad() const;
109-
110-
private:
22+
friend ostream& operator <<( ostream& s, const ObjId& i );
23+
friend istream& operator >>( istream& s, ObjId& i );
24+
25+
public:
26+
//////////////////////////////////////////////////////////////
27+
// ObjId creation
28+
//////////////////////////////////////////////////////////////
29+
/**
30+
* Returns the root Id
31+
*/
32+
ObjId()
33+
: id(), dataIndex( 0 ), fieldIndex( 0 )
34+
{
35+
;
36+
}
37+
38+
/**
39+
* Creates a ObjId using specified Id and DataIndex
40+
*/
41+
ObjId( Id i, unsigned int d, unsigned int f = 0 )
42+
: id( i ), dataIndex( d ), fieldIndex( f )
43+
{
44+
;
45+
}
46+
47+
ObjId( Id i )
48+
: id( i ), dataIndex( 0 ), fieldIndex( 0 )
49+
{
50+
;
51+
}
52+
53+
/**
54+
* Creates an ObjId by reading the path string
55+
* Returns bad on failure.
56+
*/
57+
ObjId( const string& path );
58+
59+
/**
60+
* Returns the absolute path including all array indices.
61+
*/
62+
string path() const;
63+
64+
/**
65+
* Returns the Eref matching itself.
66+
*/
67+
Eref eref() const;
68+
69+
/**
70+
* For equality check
71+
*/
72+
bool operator==( const ObjId& other ) const;
73+
bool operator!=( const ObjId& other ) const;
74+
75+
/**
76+
* For sorting
77+
*/
78+
bool operator<( const ObjId& other ) const;
79+
80+
/**
81+
* True if the data is present on the current node. Always true for
82+
* globals, which confuses the matter somewhat.
83+
*/
84+
bool isDataHere() const;
85+
86+
/// Returns true if the Element is global.
87+
bool isGlobal() const;
88+
89+
/// Returns true if we need to go off-node for calling operations
90+
bool isOffNode() const;
91+
92+
/**
93+
* Returns data entry for this object
94+
*/
95+
char* data() const;
96+
97+
/**
98+
* Returns Element part
99+
*/
100+
Element* element() const;
101+
102+
/**
103+
* Here are the data values.
104+
*/
105+
Id id;
106+
unsigned int dataIndex;
107+
unsigned int fieldIndex;
108+
109+
/**
110+
* True if the return value is bad: either returning a failure,
111+
* or the DataIndex or FieldIndex is out of range. However, this
112+
* is a node-local funtion so it can't report the FieldIndex status
113+
* in all cases.
114+
*/
115+
bool bad() const;
116+
117+
private:
111118
};
112119

113120
#endif // _OBJ_ID_H

0 commit comments

Comments
 (0)