2013-02-09 47 views
3

我正在開發一個在線判斷器類型系統,其中可能有100個左右的不可信可執行文件將全部同時運行並評估相同的輸入數據。公平,安全,高效和多語言的沙盒

我希望每個可執行文件被限制爲預先定義的資源池的CPU,內存,磁盤空間等的份額。例如,如果將資源池設置爲機器CPU的3/4,則會運行3 GB的內存,300 GB的磁盤和2個可執行文件,每個CPU將獲得3/8的CPU,1.5 GB的內存,150 GB的磁盤。如果另一個人加入,資源將被重新調整爲三個相等的片段。這是爲了防止惡意或錯誤的可執行文件竊取其他人的資源,併爲每個人提供相同的資源。理想情況下,我還希望可執行文件不受單一語言的約束(例如,讓用戶在任何他們感到舒適的方面進行開發 - C,C++,Java,Python等)。

使用整個虛擬機或類似OpenVZ似乎是矯枉過正。是否有輕量級的替代品,對每個可執行文件使用單獨的進程,同時限制資源,禁用網絡訪問,進程產卵等功能?我尋找輕量級解決方案的部分原因是,有相當多的輸入數據 - 不必將其複製到每個可執行文件,而是讓它們從共享內存中讀取。

回答

0

也許這足以爲每個進程創建不同的用戶ID,然後通過「ulimit」限制它們。在Debian下bash的的ulimit的聯機幫助:

ulimit [-HSTabcdefilmnpqrstuvx [limit]] 

提供超過可用的外殼和由它啓動的進程資源的控制,在允許這種控制系統。 -H和-S選項指定爲給定資源設置的硬限制或軟限制爲 。非root用戶一旦設置硬限制就不能增加;軟限制可以增加到硬限制的值。如果既不指定-H也不指定 ,則設置軟限制和硬限位。限制的值可以是爲資源指定的單位中的數字,也可以是硬,軟或無限的特殊值之一,分別代表當前硬限制,當前軟限制和無限制的 。如果省略限制,則會打印資源軟限制的當前值,除非給出-H選項爲 。當指定多個資源時,限制名稱和單位將打印在值的前面。其他選項解釋如下:

  -a  All current limits are reported 
      -b  The maximum socket buffer size 
      -c  The maximum size of core files created 
      -d  The maximum size of a process's data segment 
      -e  The maximum scheduling priority ("nice") 
      -f  The maximum size of files written by the shell and its children 
      -i  The maximum number of pending signals 
      -l  The maximum size that may be locked into memory 
      -m  The **maximum resident set size** (many systems do not honor this limit) 
      -n  The maximum number of open file descriptors (most systems do not allow this value to be set) 
      -p  The pipe size in 512-byte blocks (this may not be set) 
      -q  The maximum number of bytes in POSIX message queues 
      -r  The maximum real-time scheduling priority 
      -s  The maximum stack size 
      -t  The maximum amount of cpu time in seconds 
      -u  The maximum number of processes available to a single user 
      -v  The maximum amount of virtual memory available to the shell and, on some systems, to its children 
      -x  The maximum number of file locks 
      -T  The **maximum number of threads** 

我認爲限制線程爲1你可以得到公平的CPU計算時間分佈。

限制也是最大的RSS。

+0

與Docker一起使用看起來就像解決方案。 – 2014-07-17 10:43:04