Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Inquiry / Request for feedback [Service: a sandboxed JVM on a public server]  (Read 8060 times)
0 Members and 1 Guest are viewing this topic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Posted 2008-02-18 15:00:10 »

Quite recently, I got myself this dedicated server. As I was too busy at the time, and saw CommanderKeith's game, which desperately needed some reliable public server, I offered him a tiny share of mine. This was a great experience, as it turned out to be rather tricky to get things running, which would have been much harder without access to a public server. Anyway, I think there might be a demand for such a service, that delivers a minimal share of a server, for a minimal fee - hopefully just to cover the costs of my dedicated server.

I had this idea to get some feedback from the community, before I would put a lot of effort into building the website. So here it is:


Service: a sandboxed JVM on a public server

Quote
To support multiplayer in your games, you probably want a public server to connect all players to eachother. The costs and maintainance of a dedicated server, or a VirtualPrivateServer is often a big turnoff. Normally you'd only use minimal resources, to run your matching-service, chatroom or simple gameserver.

What you might need is a service that allows you to use minimal resources on a public server. For a minimal fee of 5 EUR / month, you can run your own Java application, hosting 2 serversockets, within a sandbox, on a dedicated server.

To ensure everybody gets their fair share of performance, the following rules apply:



Available CPU resources (DELL Dual XEON 3.2 GHz):
 - 66% average usage in 3 seconds
 - 20% average usage in 10 seconds
 - 5% average usage in 60 seconds
 - 2% average usage in 3600 seconds

Available bandwidth:
 - 5000kB/s average throughput in 3 seconds
 - 1500kB/s average throughput in 10 seconds
 - 500kB/s average throughput in 60 seconds
 - 100kB/s average throughput in 3600 seconds
 - 250MB traffic per day

Available resources:
 - max 48MB Java-heap, 4MB direct-memory
 - two serversockets for incoming TCP connections (port 1024+)
 - 250MB harddisk space (read/write access in your own user-directory)
 - the STDOUT and STDERR as streams visible by a webbrowser, and as downloadable files after the process is terminated.

Runtime restrictions:
 - once you exceed the available resources, your process will be restarted. You will receive a notification email, describing what happened.
 - not possible to connect to hosts with a Socket other than port 80 (further, only incoming sockets allowed) to prevent spammers/hackers from abusing this service.

For 5 EUR a month, I think it's affordable for just about anyone aspiring to get into networked games (or other services).

What are your thoughts? Would you use this service?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2008-02-18 15:11:54 »

Sounds like a pretty great service, I use a dedicated box myself atm - but having somewhere seperate to run a fixed and stable build would be great.

Quote
Available resources:
 - max 48MB Java-heap, 4MB direct-memory
 - 10MB harddisk space to upload your JAR
 - the STDOUT and STDERR as streams visible by a webbrowser, and as downloadable files after the process is terminated.
 - no read/write access to filesystem
 - once you exceed the available resources, your process will be restarted. You will receive a notification email, describing what happened.

These would probably kill my interest tho. 10MB in particular, but the memory probably also.

Kev

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2008-02-18 15:19:02 »

Thanks for your quick response!


Hm, well, the harddisk-space could probably be bumped up to 250MB, as that's not really the problem. But as you're not able to do much with it (no filesystem access) I thought 10MB was pretty much enough. I'll look into how I can both have file-access support, and keep it secure... my knowledge of the SecurityManager is pretty rusty.


The memory-limitation is kinda there to stay - I haven't got much room to spare - otherwise I'd have to double or triple my serverhosting-costs.

If there is enough demand, it wouldn't be a problem though.

Maybe another account for 10 EUR / month for 75MB heap, 15 EUR / month for 100MB heap.

Any more expensive, and you can almost afford that VPS yourself Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CommanderKeith
« Reply #3 - Posted 2008-02-18 21:47:14 »

Riven's dedicated server has been sensational for testing my game, so I'd recommend this to anyone. The latency is extremely low - even from where I am in Sydney it takes only 175 milliseconds to send a message to the Amsterdam dedicated server.

It's quite a thrill to have your game running on the internet for everyone to join in and play at once.

A big thumbs up from me Smiley


Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2008-02-18 21:57:45 »

Thanks for the feedback Keith Smiley


Kevin, how much heap would not kill your interest?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2008-02-18 22:08:09 »

64 I guess I'd see as the minimum, I've hit there before. I spose I'm assuming I'd want to grow further than my games have in the past, but then maybe once the game gets going this wouldn't be the place for it?

Is the intention that this is for fledgling games, or for fully developed masterpieces eventually?

Kev

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2008-02-18 22:25:49 »

It's mainly meant to lower the bar for those that are interested in deploying a networked game, but get frustrated by all hurdles to get there. So that's pretty much 'fledging' IMHO. I simply don't want to be held responsible for anyones business or losses due to downtime/bugs. I want to help out indies, and it would be great to breakeven with the hostingbills.


Once games grow, I think they will either need to make a a tiny profit to pay for a cheap VPS, or just optimize their gameserver. I can't get everybody the specs of a decent server, as there are only 2 CPUs, and little spare RAM on this box, and everybody has to share these. For these low fees, an aspiring indie might want to make some compromises.

For 35 EUR/month you can rent some cheap-ass VPS with a decent amount of RAM, so raising the fees anywhere near that, wouldn't make much sense right?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2008-02-19 01:17:49 »

I guess I could simply have less accounts then, with a larger heap (64M).

When more than 3 indies use it, I can get another server with 1024MB RAM.

Thanks for the feedback, and I'll see whether there is a demand for it! Wink


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CommanderKeith
« Reply #8 - Posted 2008-02-28 02:21:34 »

It’s strange that more people haven’t jumped on this.  I think it’s because the experts here already have access to a server, and other people don’t understand what a server does.

Maybe I can try to explain?

So the type of server that Riven offers is great because you can run your program on it (ie use the CPU) instead of just storing files on it (like the free web pages you can get from www.freewebs.com etc). And having this dedicated server is better than using your own internet-connected computer since you don’t have to do port-forwarding (which is difficult and must be done for those connected to the net via a router, which is probably most people) and the dedicated server’s IP address never changes, unlike many people’s internet ip does when they re-connect to the net. Also, the dedicated server is never turned off, is probably faster than your machine and has faster upload/download limits and latencies.

Since non-experts are unlikely to know that they even need a server and won’t know how to set it up anyway, I suppose the demand for this kind of thing will be low, even though it’s so useful.

Maybe people on the forum who are paying for their own dedicated server (Riven, myself (free-riding off Riven for the moment), Kingaschi (with Aevum Obscrurum?)) should see if it’s worthwhile to pool resources?

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2008-02-28 08:39:44 »

I agree. This service would be a solution waiting for people to realize the problem. Most give up before they reach this point.


Anyway, enough of the theories, I've been working on this service for a few hours last week, and I pretty much figured out most of it. I've written a bunch of tools to monitor CPU usage and network-activity (unix commandline tools rock!). As always, I'm rather busy with work, but I think this might be up and running in the next month.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2008-02-28 09:56:56 »

I'll be interested in a slot assuming prices are reasonable Smiley if only to offload the server from my current box. I'm looking seriously at Amazon  EC2 hosting atm also tho.

Kev

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2008-02-28 22:58:15 »

Hm... I kinda disliked the CPU-limitation (and termination upon exceeding), which was obviously only going to get your app offline when things are about to get fun with a few players.



So quite accidently I stumbled upon this page that explained UNIX processes, and how they can be stopped (SIGSTOP) and continued (SIGCONT). With these I can start/stop the process in a loop, once it starts to exceed the restrictions - no termination of processes!


I immediately coded it in Java, with Runtime.exec("kill -{CONT|STOP} {pid}"), but performance was horrendous (like 7% CPU usage when starting/stopping every 100ms). I kinda hoped it was the Java overhead, so I started to code it in C to write an commandline-utility that throttles the process at a specified PID.

1  
2  
3  
4  
5  
6  
7  
   while(1)
   {
      kill(pid, SIGSTOP);
      msleep(stopms);
      kill(pid, SIGCONT);
      msleep(contms);
   }


Java: 7.0% cpu usage
Native: 0.1% CPU usage Smiley



My first babysteps in C++  Wink (apart from JNI with basic math on pointers)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>







void msleep(int x)
{
    struct timespec sleeptime;
    struct timespec remaining;
    int result;              
    remaining.tv_sec = x/1000;
    remaining.tv_nsec = (x%1000)*1000000;
    do {                                
        sleeptime.tv_sec = remaining.tv_sec;
        sleeptime.tv_nsec = remaining.tv_nsec;
        result = nanosleep(&sleeptime,&remaining);
    } while(0>result && EINTR==errno);
}



int parseInt(char *arg)
{
   int num = 0;
   while(*arg)
      num = (num*10)+((*arg++)-'0');
   return num;
}



int main(int argc, char *argv[])
{
   if(argc != 4)
   {
      printf("Usage: {PID} {INTERVAL} {PERCENTAGE}\n");
      return 1;
   }

   int pid  = parseInt(argv[1]);
   int intr = parseInt(argv[2]);
   int p100 = parseInt(argv[3]);

   int work = intr * p100 / 100;
   int wait = intr - work;

   while(1)
   {
      if(kill(pid, SIGSTOP)!=0)break;
      msleep(wait);
      if(kill(pid, SIGCONT)!=0)break;
      msleep(work);
   }
}

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CommanderKeith
« Reply #12 - Posted 2008-02-29 06:52:41 »

That's so much better than killing the process, nice.  Cool

Let me know when it's ready to try my game as a test.

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2008-03-01 10:37:51 »

I had way too much fun yesterday writing my sandbox implementation/securitymanager.

I can run multiple programs in a JVM now, each with their own stdout/stderr (!), completely isolated from eachother, each with their own SecurityManager, and a System.exit(0) that actually only shuts down their own Sandbox safely (w00t), which will also be terminated when all the alive threads of the Sandbox turn out to be daemons. As some of you might have figured out, I'm making heavy use of ThreadGroups (which even Sun called a failed experiment, yet I'm very grateful they exist!), and escaping out of a ThreadGroup would mean you'd escape the Sandbox. Now my question to you: are there ways to escape from a ThreadGroup? I tried Swing.invokeLater but *luckily* it requires a RuntimePermission with the name "createClassLoader" which can be intercepted in the SecurityManager (phew!). Grin

The only disadvantage of these multiple isolated sandboxes is that they do share the heap Sad and are in the same process, so cannot be cpu-throttled individually with my own app. But i can use ThreadMXBeans to monitor the Sandbox anyway. A big advantage though is that there is only one JVM memory-footprint. I want to use these Sandboxes for evaluating the service, and maybe extremely low-end hosting, for an even lower price (to get people interested, and wanting to upgrade..?).

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CommanderKeith
« Reply #14 - Posted 2008-03-01 13:24:59 »

No idea about ThreadGroups sorry.

Sounds like you've just about made an multi virtual machone (MVM) which is meant to be pretty hard. JavaFX uses an MVM by the way...

Apparently there are problems with them though - if one program crashes it crashes the whole MVM/JVM, and you can't kill a selected program, you can only kill the whole MVM/JVM.

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #15 - Posted 2008-03-01 13:37:15 »

Hm? Kinda weird Smiley I can kill individual Sandboxes...

From outside the sandbox:
sandbox.terminate();

From inside the sandbox:
System.exit(0);


System.out.println("hello world"); ends up on the stdout of the Sandbox.


Even a OutOfMemoryException will terminate the 'offending' Sandbox (although that might not be the sandbox that uses the most memory.. Undecided)
Only a native crash can take everything down... but the SecurityManager is quite restrictive, so I doubt I'll see a native crash.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #16 - Posted 2008-03-01 13:40:58 »

My first babysteps in C++  Wink (apart from JNI with basic math on pointers)

Psst... const correctness.

And if you want to do things the C way then there's atoi, or theres the (prefered, more robust) C++ way via stringstream (see from_string about halfway down).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline CommanderKeith
« Reply #17 - Posted 2008-03-01 13:47:09 »

Hm? Kinda weird Smiley I can kill individual Sandboxes...

From outside the sandbox:
sandbox.terminate();

From inside the sandbox:
System.exit(0);

I should have been specific, I meant like doing a ctrl-c or killing the program from the windows task manager.

What stuff are you limiting the security manager to?  no reflection? 

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #18 - Posted 2008-03-01 14:07:49 »

Quote
I should have been specific, I meant like doing a ctrl-c or killing the program from the windows task manager.

What stuff are you limiting the security manager to?  no reflection?


Pretty much everything is restricted that might cause harm (SandboxIsolationSecurityManager)
  • manipulating Threads and ThreadGroups
  • loading native libraries
  • changing securitymanager
  • writing into system properties
  • reflection (on inaccessible fields/methods)
  • management with mxbeans
  • AWT/Swing... this is serverside after all

Everything left is restricted by the SandboxSecurityManager which you are able to grant permissions.




My current setup code is:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
      System.setSecurityManager(new SandboxIsolationSecurityManager());

      SandboxSecurityManager sandboxManager1 = new SandboxSecurityManager(Thread.NORM_PRIORITY);
      sandboxManager1.allowReadDir(new File(System.getProperty("java.home")));
      sandboxManager1.allowReadDir(new File("M:/java/workspace/Base/bin/"));
      sandboxManager1.allowReadDir(new File("M:/java/workspace/Components/bin/"));
      sandboxManager1.allowReadDir(new File("M:/sandbox"));
      sandboxManager1.allowWriteDir(new File("M:/sandbox"));
      sandboxManager1.allowServerSocket(3344);
      sandboxManager1.allowServerSocket(3355);
      sandboxManager1.allowSocket(new InetSocketAddress("127.0.0.1", 3344));

      SandboxSecurityManager sandboxManager2 = sandboxManager1; // me = lazy

      Runnable sandboxTask1 = createLauncher("my.jar:your.jar:their.jar", "my.mainclass", new String[]{"the args", "to pass"});
      Runnable sandboxTask2 = createLauncher("my.jar:your.jar:their.jar", "my.mainclass", new String[]{"the args", "to pass"});

      OutputStream out1 = new FileOutputStream("M:/whatever/sandbox1_stdout.txt");
      OutputStream err1 = new FileOutputStream("M:/whatever/sandbox1_stderr.txt");
      OutputStream out2 = new FileOutputStream("M:/whatever/sandbox2_stdout.txt");
      OutputStream err2 = new FileOutputStream("M:/whatever/sandbox2_stderr.txt");

      new Sandbox("FirstBox",  sandboxManager1, sandboxTask1, out1, err1);
      new Sandbox("SecondBox", sandboxManager2, sandboxTask2, out2, err2);



And this creates that Sandbox-Runnable:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
   public static final Runnable createLauncher(String classpath, String mainclass, final String[] args)
   {
      // setup classpath classloader

      String[] cpStrings = Text.split(classpath, File.pathSeparatorChar);
      URL[] cpURLs = new URL[cpStrings.length];

      try
      {
         for (int i = 0; i < cpURLs.length; i++)
            cpURLs[i] = new File(cpStrings[i]).toURI().toURL();
      }
      catch (MalformedURLException exc)
      {
         throw new RuntimeException(exc);
      }

      // invoke: public static void main(String[] args) on mainclass

      try
      {
         URLClassLoader cl = new URLClassLoader(cpURLs);
         Class< ? >[] params = new Class[] { String[].class };
         final Method method = cl.loadClass(mainclass).getMethod("main", params);

         Runnable task = new Runnable()
         {
            @Override
            public void run()
            {
               try
               {
                  method.invoke(null, new Object[] { args });
               }
               catch (Exception exc)
               {
                  exc.printStackTrace();
               }
            }
         };

         return task;
      }
      catch (Exception exc)
      {
         throw new RuntimeException(exc);
      }
   }

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CommanderKeith
« Reply #19 - Posted 2008-03-01 14:12:52 »


Pretty much everything is restricted that might cause harm
  • manipulating Threads and ThreadGroups
  • loading native libraries
  • changing securitymanager
  • writing into system properties
  • reflection
  • management with mxbeans
  • AWT/Swing... this is serverside after all

Everything left is restricted by the SecurityManager which you are able to grant permissions.


Sounds pretty watertight! Unfortunately my game needs reflection though.

Since people will be taken on trust, do you think that the restrictions might get in the way?




Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #20 - Posted 2008-03-01 14:13:06 »

Quote
Psst... const correctness.

And if you want to do things the C way then there's atoi, or theres the (prefered, more robust) C++ way via stringstream (see from_string about halfway down).


Hm... yeah, I discovered 'atoi' after writing that parseInt method, and I kinda didn't want to throw my code away Kiss

About 'const correctness', would it be harmful if I do not change my code? I don't want to build much else in C, and spending a few hours grasping all ins-and-outs of const, seems like a waste to me...? Thanks for your observation though, but it isn't obvious to me what should be changed, and how it improves the program. Sorry for my ignorance  Embarrassed

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2008-03-01 14:24:18 »

Quote
Sounds pretty watertight! Unfortunately my game needs reflection though.

Since people will be taken on trust, do you think that the restrictions might get in the way?

I (am pretty sure I) can trust you, and I do, as you currently run your programs without a SecurityManager.

You have to realize though, that enabling reflection allows you to access to sun.misc.Unsafe, nullifying the memory-location of the SecurityManager with a few tricks, or you can pretty much take over the entire OS from there. There is stuff running on that server that I don't want to lose Smiley

I certainly don't want to limit the people that I trust, and I might want to make reflection and option, but it will certainly not be available for anybody (paying for and) using this service.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #22 - Posted 2008-03-01 14:32:54 »

Update: as it turns out, you can use Reflection, as long as you do not use  {field|method}.setAccessible(true); Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #23 - Posted 2008-03-01 14:34:01 »

About 'const correctness', would it be harmful if I do not change my code? I don't want to build much else in C, and spending a few hours grasping all ins-and-outs of const, seems like a waste to me...? Thanks for your observation though, but it isn't obvious to me what should be changed, and how it improves the program. Sorry for my ignorance  Embarrassed

If it already works and you're not going to extend it then there's not much point going back and adding const correctness. But just for reference here's what I'd tweek:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
void msleep(const int x) // don't want to accidentally change your in param
{
    struct timespec sleeptime;
    struct timespec remaining;
    int result;              
    remaining.tv_sec = x/1000;
    remaining.tv_nsec = (x%1000)*1000000;
    do {                                
        sleeptime.tv_sec = remaining.tv_sec;
        sleeptime.tv_nsec = remaining.tv_nsec;
        result = nanosleep(&sleeptime,&remaining);
    } while(0>result && EINTR==errno);
}



int parseInt(const char* const arg) // both pointer is const and pointed-to data is const
{
   int num = 0;
   while(*arg)
      num = (num*10)+((*arg++)-'0');
   return num;
}



int main(int argc, char* argv[])
{
   if(argc != 4)
   {
      printf("Usage: {PID} {INTERVAL} {PERCENTAGE}\n");
      return 1;
   }

   const int pid  = parseInt(argv[1]);
   const int intr = parseInt(argv[2]);
   const int p100 = parseInt(argv[3]);

   const int work = intr * p100 / 100;
   const int wait = intr - work;

   while(1)
   {
      if(kill(pid, SIGSTOP)!=0)break;
      msleep(wait);
      if(kill(pid, SIGCONT)!=0)break;
      msleep(work);
   }
}


Since you're only using straight C here with no classes, use of const is nice and simple, basically like 'final' in Java for primatives.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #24 - Posted 2008-03-01 14:42:09 »

Thanks, will make the changes as it turns out it's not much magic. I didn't realize that I was passing pointers, instead of a copy of the pointer, like in Java (or a copy of the value at the pointer, for primitives, that is).

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #25 - Posted 2008-03-02 00:26:10 »

I wonder have you looked at http://www.jcp.org/en/jsr/detail?id=121


Runtime.exec() creates a heavyweight process everytime, you could have also started a bash and issue it commands, JNI works too offcourse.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #26 - Posted 2008-03-02 01:11:03 »

JCP121 looks like what I need, but I don't really want to wait a few years, when I can code something 'like' it in a few days.


You're right about the overhead of Runtime.exec, yet invoking bash, and sending "kill -CONT 7563" to it, creates a new 'kill' process too, so the overhead would still be there. To implement this in JNI is an interesting thought though, and I might give it a try.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #27 - Posted 2008-03-02 11:47:05 »

Have not really looked a lot into this, but I think that MyJavaServer http://www.myjavaserver.com/ give you a lot of access and even a DB completely for free, if you just want to do some tests. You just have to pass a simple test to prove that you are worthy Smiley, should be no problem. 5MB of disk space, but don´t know how much CPU power and mem you will get. I signed up a long time ago, but haven´t really used it yet...

Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #28 - Posted 2008-03-02 14:53:36 »

from URL: http://www.myjavaserver.com/exec/rsa1/.eMDHP2xXfMz94wAH1MjHvMCHnNCLjwBL1wp0f2y

Quote
The code assumes that it's being executed in a non-static context, in a class which directly or indirectly extends javax.servlet.http.GenericServlet.
Hm... way too much J2EE oriented for a game-server eh?

Quote
Log entries logged via the servlet API can be retrieved via the error log in the membersarea, which displays the last 25 records.
With only 25 lines of stdout you can forget remote debugging. The more info the better, especially when events occur hours from eachother.


It's a nice service but with 5MB of harddisk you are pretty limited, and I can add a MySQL database too... I guess Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #29 - Posted 2008-03-08 20:20:29 »

At the moment it is almost up and running. At least it works fine locally (which shouldn't be any different from running at my server)


I'm now building a UI client to transfer files to/from the server and monitor the stdout/stderr in realtime.




Client source
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
package myapp;

import craterstudio.apps.sandbox.SandboxStats;


public class Main
{
   private static SandboxStats stats;

   public static void sandbox(SandboxStats stats)
   {
      Main.stats = stats;
   }

   public static void main(String[] args)
   {
      // your app here
  }
}



Example app using sandbox-statistics
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
   public static void main(String[] args) throws Exception
   {
      for(int i=0; i<10; i++)
      {
         int secondsInterval = 3;
         String avg = String.valueOf(stats.getAverageCpuUsage(secondsInterval));
         if(avg.length() > 5) avg = avg.substring(0,5);

         System.out.println();
         System.out.println("Main.main(uptime:        "+stats.getUptime()+"ms)");
         System.out.println("Main.main(cpu-time:      "+stats.getTotalCpuTime()+"ms)");
         System.out.println("Main.main(avg. cpu-time: "+avg+"/1.000) over "+secondsInterval+" seconds");

         for(int k=0; k<65536; k++)
            for(int m=0; m<1024; m++)
               Math.sqrt(k*m);

         Thread.sleep(1000);
      }

      System.exit(0); // optional
  }





Output
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
Main.main(uptime:        1140ms)
Main.main(cpu-time:      93ms)
Main.main(avg. cpu-time: 0.031/1.000) over 3 seconds

Main.main(uptime:        2237ms)
Main.main(cpu-time:      202ms)
Main.main(avg. cpu-time: 0.067/1.000) over 3 seconds

Main.main(uptime:        3322ms)
Main.main(cpu-time:      296ms)
Main.main(avg. cpu-time: 0.098/1.000) over 3 seconds

Main.main(uptime:        4407ms)
Main.main(cpu-time:      374ms)
Main.main(avg. cpu-time: 0.093/1.000) over 3 seconds

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (22 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (55 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (30 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!