Hi,
I'm sending arrays to SFS to store in mysql.
I noticed when i send large amounts of data, SFS stops responding.
Is there anything special i need to consider ?
When i send 10 objects, all seems to work ok but it goes wrong on larger amounts.
I'm sending transforms of gameobjects with some other vars to store and retrieve later.
I store all properties of my object sepperately in mysql.
Thanks
Writing data to mysql
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Yeah - there is definitely something to consider.
(I'm in the exact same situation right now, and adding some failsafe mechanisms to the API for the next release)
Right now the API writes something like "wrong sized array or negative size array -1231" and then disconnects. Which is bad. I would rather personally that it throws away the incoming data (with a proper warning in the logfiles) and then simply continues.
A SFSArray can "only" contain 32k objects. A string can only be 32k bytes long.
Sending things as binary data and send via ByteArray. That bastard according to the SFS guys can handle 2 gb of content theoretically.
/Thomas
(I'm in the exact same situation right now, and adding some failsafe mechanisms to the API for the next release)
Right now the API writes something like "wrong sized array or negative size array -1231" and then disconnects. Which is bad. I would rather personally that it throws away the incoming data (with a proper warning in the logfiles) and then simply continues.
A SFSArray can "only" contain 32k objects. A string can only be 32k bytes long.
Sending things as binary data and send via ByteArray. That bastard according to the SFS guys can handle 2 gb of content theoretically.
/Thomas
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
I can ship you some code as an example. See below. xmlDoc is a XmlDocument BTW
Code: Select all
// Convert to string
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xmlDoc.WriteTo(xw);
// Lets put level xml into sfsobject
requestObject = new SFSObject();
requestObject.PutUtfString("sceneName", sceneName);
// SFS2X can only handle <32kb strings - lets send as byte array instead
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] levelXmlBytes = encoding.GetBytes(sw.ToString());
requestObject.PutByteArray("levelXml", new Sfs2X.Util.ByteArray(levelXmlBytes));
byte[] sceneXmlBytes = encoding.GetBytes(sceneXmlFile.text);
requestObject.PutByteArray("sceneXml", new Sfs2X.Util.ByteArray(sceneXmlBytes));
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Corresponding server side (slightly cut'n'pasted from different places, as its not a single block):
Basically I take the byte array and assemlble it back to XML - and write the xml file to the harddrive
Basically I take the byte array and assemlble it back to XML - and write the xml file to the harddrive
Code: Select all
String levelXml = new String(params.getByteArray("levelXml"));
Document doc = new SAXBuilder().build(new StringReader(levelXml));
// Write file to folder
try {
File file = new File(BASEPATH + sceneName + "/" + filename);
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(doc, writer);
Log.info(LogSystem.SERVERSYSTEM, "Wrote new xml file to " + file.getAbsolutePath());
}
catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
ok, i made some progress
I created a byte array from a serialized class and sent it to SFS.
I'm receiving it fine.
I also created the class on SFS.
I can reach the byte array server side but i'm not sure how to deserialize them to the class so i can write to mysql.
2 questions about this approach :
- is this a valid approach
- how can i deserialize ?
Any hints ?
Thanks.
I created a byte array from a serialized class and sent it to SFS.
I'm receiving it fine.
I also created the class on SFS.
I can reach the byte array server side but i'm not sure how to deserialize them to the class so i can write to mysql.
2 questions about this approach :
- is this a valid approach
- how can i deserialize ?
Any hints ?
Thanks.
Who is online
Users browsing this forum: No registered users and 46 guests